![](/img/trans.png)
[英]How to fix: Data path “” should have required property 'browserTarget' error in Angular 8 when running ng serve or npm start
[英]How to fix Angular replace bootstrap error when ng serve
我在“ng serve”命令上收到以下錯誤。 我剛剛從 git 中提取了這個,刪除了 node_modules 和 package-lock 文件,運行了 npm install 然后 ng serve。 我不知道這意味着什么,之前似乎沒有其他人遇到過這個問題
Error: TypeError: Cannot read property 'createUniqueName' of undefined
at
...\Web\Web\node_modules\@ngtools\webpack\src\transformers\replace_bootstrap.js:54:50
at Array.forEach (<anonymous>)
at standardTransform
(...\Web\Web\node_modules\@ngtools\webpack\src\transformers\replace_bootstrap.js:32:32)
at transformer (...\Web\Web\node_modules\@ngtools\webpack\src\transformers\make_transform.js:17:25)
replace_bootstrap.js:54:50 看起來像這樣:
const idPlatformBrowser = ts.factory.createUniqueName('__NgCli_bootstrap_');
replace_bootstrap.js:32:32 是這樣的:
entryModuleIdentifiers.forEach(entryModuleIdentifier => {
// Figure out if it's a `platformBrowserDynamic().bootstrapModule(AppModule)` call.
if (!(entryModuleIdentifier.parent
&& entryModuleIdentifier.parent.kind === ts.SyntaxKind.CallExpression)) {
return;
}
const callExpr = entryModuleIdentifier.parent;
if (callExpr.expression.kind !== ts.SyntaxKind.PropertyAccessExpression) {
return;
您的node_moduels
可能有問題,我認為您不應該刪除package-lock.json
。 嘗試從 git 再次拉取項目並以這種方式刪除node_modules
然后安裝:
rm -rf node_modules
npm install
它將刪除您的 node_modules/ 文件夾,然后從 package.json 重新安裝依賴項。
以下是關於package-lock.json
文件以及為什么要使用現有文件的說明: 提交並且不要刪除 package-lock.json
從網站:
一個新的開發人員來了,並從源代碼管理中獲取了項目。 他們使用 npm 安裝並看到一切正常,因為恢復的軟件包與為原始開發人員恢復的軟件包版本完全相同。 但現在他們認為“誰犯了 package-lock.json?他們不知道這是多余的嗎?” 所以他們將其從源代碼控制中刪除。 三個月后,另一個開發人員來並在代碼存儲庫的源代碼上運行 npm 安裝,但沒有任何效果。 根據 package.json 中指定的內容,下載的版本是依賴項的最新版本,或者可能是類似的版本,但具有不同的次要版本,以及開發人員認為最適合該特定版本的依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.