我跑步
node --experimental-modules simpledemo.mjs
Simple2.mjs(本书Node.js完整参考指南)
var count = 0;
export function next() { return ++count; }
function squared() { return Math.pow(count, 2); }
export function hello() {
return "Hello, world!";
}
export default function() { return count; }
export const meaning = 42;
export let nocount = -1;
export { squared };
遇到错误
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/mi/pract/simple2.mjs' imported from /home/mi/pract/simpledemo.mjs
树
tree .
.
├── simple2.msj
├── simpledemo.mjs
└── simple.js
0 directories, 3 files
导入行(通过查看以前的SO帖子进行编辑)
import * as simple2 from '/home/mi/pract/simple2.mjs';
节点版本
v14.8.0
如何解决导入问题?