angular-cli: Using the new Angular v4 Option - Could not resolve module opaque_token

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

Windows 10

Versions.

Please run ng --version. If there’s nothing outputted, please run in a Terminal: node --version and paste the result here:

@angular/cli: local (v1.0.0-beta.31, branch: master) node: 7.5.0 os: win32 x64 @angular/common: 4.0.0-beta.7 @angular/compiler: 4.0.0-beta.7 @angular/core: 4.0.0-beta.7 @angular/forms: 4.0.0-beta.7 @angular/http: 4.0.0-beta.7 @angular/platform-browser: 4.0.0-beta.7 @angular/platform-browser-dynamic: 4.0.0-beta.7 @angular/router: 4.0.0-beta.7 @angular/cli: 1.0.0-beta.31 @angular/compiler-cli: 4.0.0-beta.7

Repro steps.

Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.

The error happens when you try to run a freshly created ng4 project

Step 1: ng new my-project -ng4 --skip-install true --skip-git true --skip-tests true --skip-commit true --style scss --prefix ri --routing

Step 2 cd my-project > ng serve/build.

You will see this error: ERROR in Could not resolve module @angular/core/src/di/opaque_token

The log given by the failure.

Normally this include a stack trace and some more information.

No logs, but I think this may have to do with AOT. Not sure.

Mention any other details that might be useful.

When Beta.31 first was released, I was able to follow the exact same steps as above and everything worked.

Just a snap of my console: cli-error-ng4


Thanks! We’ll be in touch soon.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 33 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Great that it works. I think it makes sense to leave the issue open as this should not happen when running it off master.

Since I did not npm link @angular/cli after my most recent npm install, does that mean I am using the locally installed version or the master version I have on my PC?

You should now run it using the locally installed version, so the released version .31 from npmjs.

The error is because the module @angular/core/src/di/opaque_token does not seem to exist anymore in Angular 4, whereas it does exist in Angular 2.

And because Angular CLI still installs dependencies from Angular 2 it has now mixed up the two versions.

Another way to get it running (this is quite ugly) is to go to your git clone of Angular CLI and install the Angular 4 dependencies and an upgraded TypeScript there:

$ npm install @angular/core@next @angular/compiler@next @angular/compiler-cli@next @angular/tsc-wrapped@next typescript@2.1.5

I don’t recommend this though. The way to go is probably not linking @angular/cli but use the one from npmjs.

Ok, that you work with the cli master explains why it fails at both our machines, I tend to run that too.

So when you npm link you essentially work with master either way you start it. What you can probably try is run npm install --save-dev @angular/cli@latest in your project. That should force getting the package from npmjs, my suggested fix should work then.

@beeman Thanks for a quick response! I use npm link with the cli master so I always have the latest changes you guys make. I have not ventured into trying to modify any of the code though!

OK ~ I tried your workaround but I am getting the same error. Maybe I should re-install everything?

Thanks so much for your help!

err

This issue is closed but I still have the problem when using ng v4 with yarn.

Will this be fixed in next cli version ? (current 1.0.0-beta.32.3).

@Meligy your PR was just closed (not merged) right ?

I need to get your number so I can put you on speed dial! haha.

😂

Glad to hear that it’s working and that you can play around with NG4.

OK! You are the man!

So what I did was npm link @angular/cli then deleted my existing node_modules folder and did a fresh install. From there, I used ./node_modules/.bin/ng serve just like your suggestion and it works.

I am still new to package linking be it npm or yarn. Since I did not npm link @angular/cli after my most recent npm install, does that mean I am using the locally installed version or the master version I have on my PC?

Thanks so much!

OK that makes perfect sense. It did not work for me off the cuff, but I need to try a couple things. Will report back! Thanks!