简体   繁体   English

在 angular 中新建项目

[英]Creating a new project in angular

I used this command我用了这个命令

ng new hello

to create a new project in visual studio code.在 Visual Studio 代码中创建一个新项目。 It creates all the files but while installing packages, it stops and shows an error.它会创建所有文件,但在安装软件包时会停止并显示错误。 I am copying the whole error down below:我将整个错误复制到下面:

 PS E:\Angular> ng new hello
 ? Would you like to add Angular routing? Yes
 ? Which stylesheet format would you like to use? CSS
 CREATE hello/angular.json (3558 bytes)
 CREATE hello/package.json (1281 bytes)     
 CREATE hello/README.md (1022 bytes)        
 CREATE hello/tsconfig.json (489 bytes)     
 CREATE hello/tslint.json (3125 bytes)      
 CREATE hello/.editorconfig (274 bytes)     
 CREATE hello/.gitignore (631 bytes)        
 CREATE hello/browserslist (429 bytes)      
 CREATE hello/karma.conf.js (1017 bytes)    
 CREATE hello/tsconfig.app.json (210 bytes) 
 CREATE hello/tsconfig.spec.json (270 bytes)
 CREATE hello/src/favicon.ico (948 bytes)   
 CREATE hello/src/index.html (291 bytes)
 CREATE hello/src/main.ts (372 bytes)
 CREATE hello/src/polyfills.ts (2835 bytes)
 CREATE hello/src/styles.css (80 bytes)
 CREATE hello/src/test.ts (753 bytes)
 CREATE hello/src/assets/.gitkeep (0 bytes)
 CREATE hello/src/environments/environment.prod.ts (51 bytes)
 CREATE hello/src/environments/environment.ts (662 bytes)
 CREATE hello/src/app/app-routing.module.ts (246 bytes)
 CREATE hello/src/app/app.module.ts (393 bytes)
 CREATE hello/src/app/app.component.html (25755 bytes)
 CREATE hello/src/app/app.component.spec.ts (1056 bytes)
 CREATE hello/src/app/app.component.ts (209 bytes)
 CREATE hello/src/app/app.component.css (0 bytes)
 CREATE hello/e2e/protractor.conf.js (808 bytes)
 CREATE hello/e2e/tsconfig.json (214 bytes)
 CREATE hello/e2e/src/app.e2e-spec.ts (638 bytes)
 CREATE hello/e2e/src/app.po.ts (301 bytes)
| Installing packages...npm WARN deprecated tslint@6.1.2: TSLint has been deprecated in favor of 
 ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.
npm WARN deprecated request@2.88.2: request has been deprecated, see 
 https://github.com/request/request/issues/3142
 npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 
 15x less dependencies.
 npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure 
 binaries. Upgrade to fsevents 2.
 npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
 npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
 E:\Angular\hello\parser -> E:\Angular\hello\node_modules\@babel\parser\bin\babel-parser.js
 E:\Angular\hello\acorn -> E:\Angular\hello\node_modules\acorn\bin\acorn
 E:\Angular\hello\ansi-html -> E:\Angular\hello\node_modules\ansi-html\bin\ansi-html
 E:\Angular\hello\atob -> E:\Angular\hello\node_modules\atob\bin\atob.js
 E:\Angular\hello\cssesc -> E:\Angular\hello\node_modules\cssesc\bin\cssesc
 E:\Angular\hello\esparse -> E:\Angular\hello\node_modules\esprima\bin\esparse.js
 E:\Angular\hello\esvalidate -> E:\Angular\hello\node_modules\esprima\bin\esvalidate.js
 E:\Angular\hello\image-size -> E:\Angular\hello\node_modules\image-size\bin\image-size.js
 E:\Angular\hello\jsesc -> E:\Angular\hello\node_modules\jsesc\bin\jsesc
 E:\Angular\hello\loose-envify -> E:\Angular\hello\node_modules\loose-envify\cli.js
 E:\Angular\hello\miller-rabin -> E:\Angular\hello\node_modules\miller-rabin\bin\miller-rabin
 E:\Angular\hello\mime -> E:\Angular\hello\node_modules\mime\cli.js
 E:\Angular\hello\blocking-proxy -> E:\Angular\hello\node_modules\blocking-proxy\built\lib\bin.js
 E:\Angular\hello\json5 -> E:\Angular\hello\node_modules\json5\lib\cli.js
 E:\Angular\hello\mkdirp -> E:\Angular\hello\node_modules\mkdirp\bin\cmd.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 
 (node_modules\rollup\node_modules\fsevents):
 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted 
{"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} 
 (current: {"node":"12.18.0","npm":"6.14.4"})
 npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0
 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\watchpack- 
 chokidar2\node_modules\chokidar\node_modules\fsevents): 
 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted 
 {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\webpack-dev- 
server\node_modules\chokidar\node_modules\fsevents):  
 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted 
 {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code EEXIST
npm ERR! path E:\Angular\hello\node_modules\browserslist\cli.js
npm ERR! dest E:\Angular\hello\browserslist
 npm ERR! EEXIST: file already exists, cmd shim 'E:\Angular\hello\node_modules\browserslist\cli.js' - 
 > 'E:\Angular\hello\browserslist'
 npm ERR! File exists: E:\Angular\hello\browserslist
 npm ERR! Remove the existing file and try again, or run npm
 npm ERR! with --force to overwrite files recklessly.

 npm ERR! A complete log of this run can be found in:
 npm ERR!     C:\Users\Dell\AppData\Roaming\npm-cache\_logs\2020-06-05T18_42_48_450Z-debug.log
 × Package install failed, see above.
 The Schematic workflow failed. See above.

I have tried re-installing everything.我已经尝试重新安装所有内容。 I have also tried updating my angular cli.我也尝试过更新我的 angular cli。 I have also tried uninstalling my angular cli and cleaning the cache and then re-installing angular cli.我还尝试卸载我的 angular cli 并清理缓存,然后重新安装 angular cli。 But none of this is working.但这些都不起作用。 I googled alot but coud not get anything to work.我用谷歌搜索了很多,但没有得到任何工作。 I have been trying to resolve this error for a week now.我已经尝试解决这个错误一周了。 I don't know what else to do.我不知道还能做什么。 Any help would be appreciated.任何帮助,将不胜感激。

UPDATE:更新:

   internal/modules/cjs/loader.js:969
   throw err;

^ ^

 Error: Cannot find module 
'C:\Users\Dell\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] 
(internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
 code: 'MODULE_NOT_FOUND',
 requireStack: []

Delete the node_modules directory.删除 node_modules 目录。

Run npm install again.再次运行npm install

Hope it helps you.希望它可以帮助你。

  1. uninstall angular cli if you have already installed it如果您已经安装了 angular cli,请卸载它

    npm uninstall -g @angular/cli
  2. Delete the C:\Users\Dell\AppData\Roaming\npm\node_modules\@angular folder if it still exists after the uninstall如果卸载后C:\Users\Dell\AppData\Roaming\npm\node_modules\@angular文件夹仍然存在,请删除它

  3. reinstall angular-cli globally全局重新安装 angular-cli

     npm install -g @angular/cli

here are my notes (from cmd):这是我的笔记(来自 cmd):

node -v // must have 10.9.0 or later node -v // 必须是 10.9.0 或更高版本

npm install -g @angular/cli

ng new my-app

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM