简体   繁体   English

使用 --experimental-modules 后出现“ESM 模块加载器是实验性的”的 NodeJs 错误

[英]NodeJs error of 'The ESM module loader is experimental' after using --experimental-modules

I wrote this on package.json我在 package.json 上写了这个

"start:server": "nodemon --experimental-modules --es-module-specifier-resolution=node src/index server.js"

OR或者

 "start:server": "nodemon --experimental-modules server.js"

server.js服务器.js

import { LoginPageModule } from './src/app/login/login.module';

Error:错误:

(node:16628) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(

You need to add the .js to the import, unless you also add --experimental-specifier-resolution=node .您需要将.js添加到导入中,除非您还添加--experimental-specifier-resolution=node

This changes node's default explicit setting which requires file extensions to be set, which then allows files without an extension to be seen as .js files.这会更改节点的默认explicit设置,该设置需要设置文件扩展名,然后允许将没有扩展名的文件视为.js文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 节点 --experimental-modules - 错误:找不到模块 - Node --experimental-modules - Error: Cannot find module (node:9511) ExperimentalWarning: ESM 模块加载器是实验性的 - (node:9511) ExperimentalWarning: The ESM module loader is experimental 设置了 --experimental-modules 的“不能在模块外使用导入语句” - "Cannot use import statement outside a module" with --experimental-modules set node --experimental-modules,请求的模块不提供名为的导出 - node --experimental-modules, requested module does not provide an export named 使用--experimental-modules将ES6导入Node - ES6 imports in Node with --experimental-modules pm2 不适用于实验模块标志 - pm2 not working with experimental-modules flag 带有 --experimental-modules 标志的 VS Code 调试 - VS Code debug with --experimental-modules flag 如何将本机节点JS模块(--experimental-modules)与Mocha一起使用 - How do I use a Native Node JS Module (--experimental-modules) with Mocha 使用实验模块运行节点脚本时找不到.ts 模块 - Cannot find .ts module while running node script with experimental-modules 使用“--experimental-modules”编译时如何修复“ReferenceError: require is not defined”错误? - How to fix "ReferenceError: require is not defined" error when compiling with "--experimental-modules"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM