node.js - 类型错误 : Cannot read property 'onReady' of undefined

标签 node.js ecmascript-6 es6-modules

当我运行 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/

相关文章:

javascript - 在 es6 中,函数参数列表中的花括号有什么作用?

javascript - Babel 在 Node.js 中不起作用 SyntaxError : Unexpected identifier

javascript - 我应该避免在模块中使用顶级变量吗?

node.js - 根据脚本内容恢复 node-modules 和 bower_components

javascript - typescript 。使用 "import from"时是否仍需要三斜杠引用

node.js - 向机器人执行 POST 时出现 502(错误网关)

javascript - ES2015 (ES6) 类中类构造函数的闭包

javascript - ':' 冒号在 JavaScript 的导入中有什么作用?

node.js - “AWSCognito”未定义

json - 解析 Node 命令行参数