【问题标题】:How to fix Angular replace bootstrap error when ng serveng服务时如何修复Angular替换引导错误
【发布时间】:2021-03-09 16:59:10
【问题描述】:

“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;

【问题讨论】:

    标签: angular npm angular-cli


    【解决方案1】:

    您的node_moduels 可能有问题,我认为您不应该删除package-lock.json。尝试再次从 git 中拉取项目并以这种方式删除 node_modules 然后安装:

      rm -rf node_modules
    
       npm install
    

    它将删除您的 node_modules/ 文件夹,然后从 package.json 重新安装依赖项。

    这里是关于package-lock.json 文件以及为什么要使用现有文件的说明:Commit and do not delete package-lock.json

    来自网站:

    一位新的开发人员来了,并从源代码管理中获取了项目。他们使用 npm 安装并查看一切正常,因为软件包 恢复的版本与为 原开发商。但现在他们认为“谁犯了 包锁.json?他们不知道这是多余的吗?”所以他们删除了它 从源代码控制。三个月后,另一个开发者来了 在代码存储库的源代码上运行 npm install ,只有什么 不再工作了。下载的版本取决于 package.json 中指定的内容,最新版本的 依赖关系或类似的版本,但具有不同的次要 版本,以及开发人员认为最好的依赖项 对于那个特定的版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-12
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 2019-08-06
      • 1970-01-01
      相关资源
      最近更新 更多