在Next.js项目中使用mjs

时间:2019-06-12 03:53:35

标签: next.js webpack-4

当我在Next.js项目中使用mjs时,遇到以下错误:

Can't reexport the named export 'getLastPosition' from non EcmaScript module (only default export is available)
ModuleDependencyError: Can't reexport the named export 'getLastPosition' from non EcmaScript module (only default export is available)
    at Compilation.reportDependencyErrorsAndWarnings (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1374:21)
    at D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1168:10
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\Hook.js:154:20)
    at Compilation.finish (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1163:28)
    at D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compiler.js:622:17
    at _done (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:9:1)
    at eval (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:31:22)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
ModuleDependencyError: Can't reexport the named export 'getLastPosition' from non EcmaScript module (only default export is available)
    at Compilation.reportDependencyErrorsAndWarnings (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1374:21)
    at D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1168:10
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\Hook.js:154:20)
    at Compilation.finish (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1163:28)
    at D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compiler.js:622:17
    at _done (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:9:1)
    at eval (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:31:22)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
ModuleDependencyError: Can't reexport the named export 'getLastPosition' from non EcmaScript module (only default export is available)
    at Compilation.reportDependencyErrorsAndWarnings (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1374:21)
    at D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1168:10
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\Hook.js:154:20)
    at Compilation.finish (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compilation.js:1163:28)
    at D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\webpack\lib\Compiler.js:622:17
    at _done (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:9:1)
    at eval (eval at create (D:\WorkHouse\scenario-bus\scenario-bus-fe-console\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:31:22)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)

Next.js似乎无法使用以下代码。

export { getTrackSplit, getTrack, getLastPosition } from './webclient/position.mjs';

也不执行此代码:

export * from './webclient/position.mjs';

那么,如何在Next.js项目中使用mjs?

1 个答案:

答案 0 :(得分:0)

这是我的错。我忘了转移图书馆。编译mjs库后,它可以正常工作。