How to fix Angular replace bootstrap error when ng serve

Viewed 837

I get following error on 'ng serve' command. I have just pulled this from git, deleted node_modules and package-lock file, ran npm install and then ng serve. I've no idea what this means and nobody else seemed to have this issue before

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 looks like this:

const idPlatformBrowser = ts.factory.createUniqueName('__NgCli_bootstrap_');

replace_bootstrap.js:32:32 is this:

 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;
1 Answers

There is maybe something wrong with your node_moduels and I dont think you should remove package-lock.json. Try pull the project again from git and remove node_modules this way and then install:

  rm -rf node_modules

   npm install

It will remove your node_modules/ folder and then reinstall the dependencies from package.json.

Here is an explanation about package-lock.json file and why you should use the existing one:Commit and do not delete package-lock.json

From site:

A new developer comes and gets the project from source control. They use npm install and see that everything works perfectly, because the packages restored are the exact same versions as the ones restored for the original developer. But now they think "who committed package-lock.json? Don't they know it's redundant?" so they remove it from source control. Three months later another developer comes and runs npm install on the source from the code repository, only nothing works anymore. The versions that were downloaded are, depending on what is specified in package.json, the latest version of the dependency or maybe a version similar, but with a different minor version, and with the dependencies that the developers thought best for that particular version.

Related