angular cli 必须使用 import 来加载 ES 模块

标签 angular command-line-interface

所以我已经使用 npm install -g @angular/cli 安装了 angular 并更新了 npm,但是如果我尝试在终端中运行 ng,我会得到这个输出。在确定我没有搞砸之前,我不想编辑这些文件

Unknown error: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/local/lib/node_modules/@angular/cli/node_modules/is-promise/index.js 
require() of ES modules is not supported. 
require() of /usr/local/lib/node_modules/@angular/cli/node_modules/is promise/index.js from /usr/local/lib/node_modules/@angular/cli/node_modules/run-async/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. 
Instead rename /usr/local/lib/node_modules/@angular/cli/node_modules/is-promise/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/local/lib/node_modules/@angular/cli/node_modules/is-promise/package.json.

最佳答案

从/usr/local/lib/node_modules/@angular/cli/node_modules/is-promise/package.json 中删除了 "type": "module"

关于angular cli 必须使用 import 来加载 ES 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61428143/

相关文章:

javascript - 为什么 ES6 生成器函数在 Angular 6 和 Chrome 开发者工具上给出不同的结果

angular - 在 index.html 中重复根标签

Java Rsync 逃逸空间

command-line-interface - 如何为 Vorpal 应用程序的选项添加可变参数支持

java - 如何检测java应用程序中运行JVM的终端

angular - 将服务注入(inject)angular2中的服务

javascript - 如何在 Angular 2 Webpack 中使用 WOW.js?

angular - 我收到 "Property ' router' does not exist on type 'SigninComponent' ."while using this.router.navigate(['/dashboard']);在 Angular 4

rust - 当没有提供命令时,Clap 有什么直接的方法来显示帮助吗?

cordova - 如何使用 Phonegap CLI 创建/构建本地应用程序