答案 0 :(得分:4)
检查您是否在终端的项目文件夹中
答案 1 :(得分:1)
首先检查节点
node -v
和npm正确安装
npm -v
然后再次尝试
npm install -g npm@latest
然后将其添加到ts文件
const _core = require("@angular/core");
答案 2 :(得分:0)
首先确保您安装了@angular/core
,否则请运行:
npm install @angular/core
这应该在您的node_module中安装@angular/core
,并在package.json
中自行更新。还要确保您没有使用旧版本的节点和NPM,否则从您的终端运行:
npm install npm@latest -g
然后你可以添加到你的js文件中。
const core_1 = require("@angular/core");
答案 3 :(得分:0)
这就是我在机器上解决这个问题的方法。
我第一次跑npm install @angular/core
。
然后我跑了npm install --save
。
当两个安装都成功完成后,我运行npm serve
并收到错误消息
"Versions of @angular/compiler-cli and typescript could not be determined.
The most common reason for this is a broken npm install.
Please make sure your package.json contains both @angular/compiler-cli and typescript in
devDependencies, then delete node_modules and package-lock.json (if you have one) and
run npm install again."
然后我删除了我的node_modules文件夹以及我的package-lock.json文件夹。
删除这些文件夹后,我再次运行npm install --save
。
我跑了npm start
并收到了另一个错误。这个错误说Error: Cannot find module '@angular-devkit/core'
。
我跑了npm install @angular-devkit/core --save
。
最后,我跑了npm start
,项目开始了!
答案 4 :(得分:0)
由于某些权限异常,codeany中的node-sass存在一些问题。 解决方法是转至/ usr / lib / node_modules / @ angular / cli /并删除node_modules文件夹,然后再次运行sudo npm install 使用ng new创建一个新项目并尝试运行它。它会起作用
答案 5 :(得分:0)
在此项目文件夹中运行npm install
以安装所有依赖项。
确保使用最新版本的CLI(下面的升级指南)
运行ng serve
以查看应用的运行情况(如果npm start
失败,请尝试ng serve
。)
运行以下命令 - 仅在Mac / Linux上使用“sudo”。
sudo npm uninstall -g angular-cli @angular/cli
npm cache clean --force
sudo npm install -g @angular/cli
从项目目录中删除'node_modules'文件夹和'package-lock.json'文件
按给定顺序运行以下命令
npm install
npm install --save-dev @angular-devkit/build-angular
npm link