Node --experimental-modules - Error: Cannot find module

后端 未结 3 1318
忘了有多久
忘了有多久 2021-02-02 07:20

I am getting an error when trying to import a local file, though no problem when using npm packages.

server.js

import express from \'express\'
import n         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-02 07:58

    on node 12 you have 2 options:

    1. use type="module" on package.json, experimental modules and specify extensions with specidier-resolution like this: node --experimental-modules --es-module-specifier-resolution=node src/index

    2. or not using specifier-resolution. Keep in mind you'll have to specify the extension of your files every where.

提交回复
热议问题