node --experimental-modules, requested module does not provide an export named

前端 未结 6 1951
孤街浪徒
孤街浪徒 2020-12-05 06:51

I\'ve installed Node 8.9.1 (same problem happens in v10.5.0).

I\'m trying to use named imports from npm packages in a file with the .mjs



        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 07:11

    @machineghost answer works. I remember also adding 'type':'module' to package.json along with using esm with node v12(LTS) and it worked fine.## Heading ##

    I updated my node to v14(current) and I got an error

    C:\Users\andey\Documents\Project\src\app.js:1
    Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: 
    C:\Users\andey\Documents\Project\src\app.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1217:13) {
    code: 'ERR_REQUIRE_ESM'
    }
    

    To fix it I had to remove 'type':'module' from package.json.

    source

提交回复
热议问题