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

前端 未结 6 1949
孤街浪徒
孤街浪徒 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条回答
  •  误落风尘
    2020-12-05 07:17

    You have to use .mjs extension.

    Once this has been set, files ending with .mjs will be able to be loaded as ES Modules.

    reference: https://nodejs.org/api/esm.html

    Update:

    Looks like you haven't export the method yet.

    Suppose i have hello.mjs with content

    export function sayHello() {
        console.log('hello')
    }
    

    i can use it in index.mjs like this

    import {sayHello} from './hello.mjs'
    sayHello()
    

提交回复
热议问题