当我运行 node ./myapp.js
时,我得到了
(node:14122) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/cjs/loader.js:637
module.reflect.onReady((reflect) => {
^
TypeError: Cannot read property 'onReady' of undefined
at Module.load (internal/modules/cjs/loader.js:637:22)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
at Function.Module._load (internal/modules/cjs/loader.js:558:3)
at Module.require (internal/modules/cjs/loader.js:663:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/ecarroll/code/sw/source-water/sw-input/node_modules/psl/index.js:14:19)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
最佳答案
这里的关键是,
(node:14122) ExperimentalWarning: The ESM module loader is experimental.
此错误和后续类型错误
TypeError: Cannot read property 'onReady' of undefined
是由存在引起的,
NODE_OPTIONS=--experimental-modules
您应该取消定义或设置它NODE_MODULES=""Node ...
If you run Node with --experimental-modules then,
It's important to note here that
.mjs
isn't only about file extensions. running node with the--experimental-modules
flag also means that ES6 module specifiers must be valid urls, so the extension has to be included in the import statement, e.g.import x from './x.mjs
关于node.js - 类型错误 : Cannot read property 'onReady' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54883272/