gpt4 book ai didi

angularjs - Ubuntu如何运行ng命令

转载 作者:行者123 更新时间:2023-12-04 19:01:08 24 4
gpt4 key购买 nike

在 Ubuntu 16.04 中,我使用以下命令安装了 nodejs:

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

为了确认,我使用了命令 which nodejs它返回

/usr/bin/nodejs



我想运行一个 Angular 项目。我还创建了“node_modules”文件夹并更新了“Angular CLI”。但是, ng命令在终端中不起作用。

已编辑

以下是我的 package.json 内容:
{
"name": "angular",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular-devkit/core": "^0.2.0",
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.6.7",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
}

空白终端在下面的屏幕中给出:

enter image description here

我在运行命令后看到 npm install -g @angular/cli出现以下错误:

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib' npm ERR! at Error (native) npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib'] npm ERR! errno: -13, npm ERR!
code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/local/lib' } npm ERR! npm ERR! Please try running this command again as root/Administrator.



已编辑 2

现在我在放置 ng serve 命令后看到:

niladri@niladrib:/var/www/html/ngAngular$ ng serve /usr/local/lib/node_modules/@angular/cli/models/config/config.js:17 constructor(_configPath, schema, configJson, fallbacks = []) { ^

SyntaxError: Unexpected token = at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object. (/usr/local/lib/node_modules/@angular/cli/models/config.js:3:18) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10)

最佳答案

Angular-cli 有一定的先决条件,其中包括节点版本 > 6.9,如下所示:

https://github.com/angular/angular-cli#prerequisites

要将节点更新到最新版本,我们可以遵循:

https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

关于angularjs - Ubuntu如何运行ng命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49777248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com