【问题标题】:Creating a new project in angular用角度创建一个新项目
【发布时间】:2023-03-04 01:59:02
【问题描述】:

我使用了这个命令

ng new hello

在 Visual Studio 代码中创建一个新项目。它会创建所有文件,但在安装软件包时,它会停止并显示错误。我将整个错误复制到下面:

 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.

我已尝试重新安装所有内容。我也尝试过更新我的 Angular cli。我还尝试卸载我的 angular cli 并清理缓存,然后重新安装 angular cli。但这些都不起作用。 我用谷歌搜索了很多,但没有得到任何工作。我已经尝试解决这个错误一周了。我不知道还能做什么。 任何帮助,将不胜感激。

更新:

   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: []

【问题讨论】:

    标签: angular visual-studio-code angular-cli


    【解决方案1】:

    这是我的笔记(来自 cmd):

    node -v // 必须是 10.9.0 或更高版本

    npm install -g @angular/cli

    ng new my-app

    【讨论】:

      【解决方案2】:
      1. 如果你已经安装了 Angular cli,请卸载它

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

      3. 全局重新安装 angular-cli

        npm install -g @angular/cli
        

      【讨论】:

        【解决方案3】:

        删除 node_modules 目录。

        再次运行npm install

        希望对你有帮助。

        【讨论】:

        • 让我试试这个。会告诉你的。
        • 删除了目录,在 npm install 之后它给了我 Module Not Found 错误。更新了我的问题以添加错误
        • 好的,这意味着您的 package.json 不包含 angular/cli。只需使用npm install -g @angular/cli再次安装即可
        • 我尝试了这个链接stackoverflow.com/questions/20711240/…,我的错误得到了解决。感谢您的帮助。
        • 好,伙计。再见
        猜你喜欢
        • 2020-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-16
        • 2019-02-12
        • 2021-08-20
        • 2020-04-08
        • 2023-03-10
        相关资源
        最近更新 更多