51

I renamed my Angular 4 project folder from auction-life to auction-05-life and replaced 3 occurrences of the old project name in:

  • angular-cli.json Line 4
  • app.e2e-spec.ts Line 3
  • package.json Line 2

I then ran ng serve and got this:

You seem to not be depending on "@angular/core". This is an error.

Edit: Following the instructions in the comments below, I restarted the terminal window, ensured I was in the correct project folder auction-05-life, ran npm install then ng serve and this time got a different exception:

module.js:471
    throw err;
    ^
Error: Cannot find module 'heimdalljs-logger'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
...
erikvimz
  • 5,256
  • 6
  • 44
  • 60
Liwy
  • 511
  • 1
  • 4
  • 5
  • Tried `./node_modules/.bin/ng serve` ? – Rajez Aug 26 '17 at 04:16
  • I doubt with three occurrences of the old project name sentence. – micronyks Aug 26 '17 at 04:16
  • Are you sure you're in the correct folder when you run `ng serve`, where `@angular/core` is installed in `node_modules` and is present in `node_modules`? – Lazar Ljubenović Aug 26 '17 at 05:30
  • Restart the terminal window – Vega Aug 26 '17 at 07:57
  • You seem to have somewhere a hardcoded path. Look for that. Otherwise, as you said you have the option to: remove all node-modules, uninstall angular-cli (instructions are on angular cli page, very useful) it. And run npm install and install angular-cli again. – Vega Aug 26 '17 at 19:50

7 Answers7

38
  1. Search in your project wherever the old name is used.
  2. In Visual Studio Code search can be done by using the search bar provided.
  3. Replace old name with your new name.
  4. Rename the project folder name as well and you are done.
  5. If some error occurs while running your project , delete the node_modules and do "npm install".Everything will be fine and running again.
daksh khetarpal
  • 481
  • 4
  • 5
36
  1. Modify Project name in angular.json file (Replace all occurrences of the old name in angular.json)

  2. Rename Project folder name.

  3. Delete node_modules folder from your project directory.

  4. Run npm install command.

  5. Finally run ng serve command.

27px
  • 430
  • 5
  • 16
Reza
  • 361
  • 3
  • 2
14

As of this writing, the Angular-cli commandline doesn't do renaming. So, this is what i did (manually):

1. First, see how really invested the old name is in the project by searching the "old name". On Linux, i used simple grep as.

grep -ir "oldname" .

That showed so many files, most of them under /node_modules. So i removed the /node_modules (and will use npm install after i finish the rename).

2. Next, i did Linux find & replace command against the files in current folder as follows (source sited at bottom):

cd your folder
sed -i 's/oldName/newName/g' *

Finally, don’t forget to do npm install on the current directory to install dependencies listed in your package.json (remember we removed node_modules that had old name)

** Credits:

Find replace "sed" command is from: How to replace a string in multiple files in linux command line

salah-1
  • 1,299
  • 11
  • 15
  • The idea was very helpful. Unfortunately, it was not enough. The search and replace under Linux could not capture all the files. I still had to use the search & replace function in VSCode to replace most of the files. Somehow the old name was still found in the package.json, which I had to change manually. Note: To optimize the search process, remove the node_modules folder first. Thanks for sharing! – omostan Jun 24 '21 at 12:57
4
1. Open your project directory with "Visual Studio Code"
2. Usually Ctrl+Shift+H enter "old project name" and replace "new project name" it everywhere Ctrl+Alt+Enter.
3. Delete "node_modules" folder from your project directory.
4. Rename project folder name to "new project name".
5. Run "npm install" command.

Finally run "ng serve" command.
Hoan Danh
  • 51
  • 3
2

With macOS you go to your angular project folder, and use sed command to replace old name by the new that you want:

LC_CTYPE=C && LANG=C && find * -type f -exec sed -i "" "s/old-angular-project-name/new-name/g" {} +
Walterwhites
  • 1,287
  • 13
  • 9
0

If you are not familiar with bash scripting but with your IDE, you always can perform recursive search in your files (usually Ctrl+Shift+F) and replace it everywhere - Ctrl+Alt+Enter on VSCode. Visual Studio Code Example

slava
  • 791
  • 1
  • 11
  • 26
0

In the last version of Angular (13 ) no use of the Project name in the code so to change the Project folder name you need only to change the name of the folder and run you app is like this.

  • 2
    angular.json still references the Project Name in multiple configurations such as outputpath, defaultProject and browserTarget – Melvin Otieno May 27 '22 at 11:59