我已经在这个问题上纠结了好几天了。我做了一些研究,但没有结果。在“ng serve”之后,终端总是报告:
> ./node_modules/@angular/router/fesm2020/router.mjs - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js):
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '\node_modules\@angular\compiler-cli\node_modules\@babel\core\' imported from \node_modules\@angular\compiler-cli\bundles\linker\babel\index.js
Did you mean to import @babel/core/lib/index.js?
at legacyMainResolve (internal/modules/esm/resolve.js:225:9)
at packageResolve (internal/modules/esm/resolve.js:648:14)
at moduleResolve (internal/modules/esm/resolve.js:696:18)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
at Loader.resolve (internal/modules/esm/loader.js:88:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)
at link (internal/modules/esm/module_job.js:55:36)
我的package.json如下所示:
"devDependencies": {
"@angular-devkit/build-angular": "^13.0.2",
"@angular/cli": "^13.0.2",
"@angular/compiler-cli": "~13.0.1",
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.7",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.8",
"@types/file-saver": "^2.0.3",
"@types/jasmine": "~3.8.2",
"@types/node": "^16.7.10",
"@types/xlsx": "0.0.36",
"babel-loader": "^8.2.3",
"jasmine-core": "~3.8.0",
"karma": "~6.3.4",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.1",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.4.4",
"webpack": "^5.66.0"}
而我的.babelrc是:
{"presets": ["@babel/preset-env"]}
你能给予我一些建议吗?谢谢!
1条答案
按热度按时间dgsult0t1#
我遇到了同样的问题。node_modules中一定有一些奇怪的缓存。我不知道发生了什么,但我可以通过运行..
rm -rf node_modules
然后
npm install
希望对你有用!