2

Pretty simple code. But having the error cannot find module '@angular/core'.

course.component.ts

import {Component} from '@angular/core'


@Component({
    selector: 'courses'
})
export class CoursesComponent{

}

typings.json

 {
  "ambientDependencies": {
    "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
 }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
   "exclude": [
   "node_modules",
   "typings/main",
   "typings/main.d.ts"
  ]
}

package.json

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
   "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",
   "tsc": "tsc",
   "tsc:w": "tsc -w",
   "lite": "lite-server",
   "typings": "typings",
   "postinstall": "typings install"
  },
   "license": "ISC",
   "dependencies": {
   "angular2": "2.0.0-beta.7",
   "bootstrap": "^3.3.6",
   "es6-promise": "^3.0.2",
   "es6-shim": "^0.33.3",
   "reflect-metadata": "0.1.2",
   "rxjs": "5.0.0-beta.2",
   "systemjs": "0.19.22",
   "zone.js": "0.5.15"
  },
 "devDependencies": {
  "concurrently": "^2.0.0",
  "lite-server": "^2.1.0",
   "typescript": "^1.7.5"
  }
}

I know this kind of question has been answered many times. But due to my ignorance, I still don't know.

Thanks for the help.

EDIT

My files are organized ascapture

6 Answers 6

5

For me it was due to the typescript module not selected correctly. So I selected same module value of "tsconfig.json File -> compilerOptions -> module: commonjs " at visual studio project properties. enter image description here

Sign up to request clarification or add additional context in comments.

Comments

2

Originally I downloaded the quick start seed from a course on udemy.com. Obviously the course was old. And something was mess up. I have to remind the instructor to correct it

Now I re-download the quick start from angular web site. The files structure is completely different from my original one. For example, it has a e2e folder and tslint.json. The package.json file is under thr root folder etc. tsconfig.json is in src folder.

A lot of changes, now it is working. Thanks everybody's hint.

Comments

1

It seems that your dependencies are using the package naming before RC versions.

This is explained here. In short, you need to add @angular/core (and the rest of the dependencies) in the package.json

EDIT: package.json

{
    "name": "angular2-quickstart",
    "version": "1.0.0",
    "scripts": {
        "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",
        "tsc": "tsc",
        "tsc:w": "tsc -w",
        "lite": "lite-server",
        "typings": "typings",
        "postinstall": "typings install"
    },
    "license": "ISC",
    "dependencies": {
        "@angular/common": "<your desired angular version>",
        "@angular/compiler": "<your desired angular version>",
        "@angular/core": "<your desired angular version>",
        "@angular/forms": "<your desired angular version>",
        "@angular/http": "<your desired angular version>",
        "@angular/platform-browser": "<your desired angular version>",
        "@angular/platform-browser-dynamic": "<your desired angular version>",
        "@angular/router": "<your desired angular version>",
        "bootstrap": "^3.3.6",
        "es6-promise": "^3.0.2",
        "es6-shim": "^0.33.3",
        "reflect-metadata": "0.1.2",
        "rxjs": "5.0.0-beta.2",
        "systemjs": "0.19.22",
        "zone.js": "0.5.15"
    },
    "devDependencies": {
        "concurrently": "^2.0.0",
        "lite-server": "^2.1.0",
        "typescript": "^1.7.5"
    }
}

On the Angular QuickStart package.json you have a clear picture of this example. Please, devote some time on the docs to make customizations according to your Angular version.

Hope this helps.

6 Comments

I am not sure how to do it. Please explain it with code, What I have to do in package.json?
@angular/core name change appeared after the beta versions (RC and final). What Angular version are you changing to?
The question is that even I downloaded the quick start and run npm start. It still throws the error.
Silly question, did you try to run npm install after changing the package.json?
No, I just get rid of all. And download a fresh quick-start.Try to run it.
|
1

To me on Ionic 3 project, works just updating the typescript to the latest version

npm i --save-dev typescript@latest

Then, run:

npm update

If you have problems with ionic serve, just run:

npm install

To see more details on how to adjust VSCode IDE to "hide" this problem, see: https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions

Comments

1

I had this same error but the solution was different for me, so I'll post here for anyone else that may have the same issue. I had cloned a repository from GitHub and I had this error and other similar errors on my import statements. I figured there were some files missing since there was a .gitignore. I ran the command npm install and it installed missing packages/files. It also resolved the error "No projects support the 'build' target" when trying to run npm build.

Comments

0

That problem can be arised only if there doesn't exist any such file or folder So, please Look for a folder named "node_modules" which should be present at the same place where your package.json, tsconfig.json exists and then follow this node_modules-> @angular -> core

3 Comments

this edit is not of much use, just look inside your node_modules and search for @angular folder
There is a angular2 folder inside node_modules. There is core.js inside angular2 folder.
If you are importing from @angular/core then there has to be a folder named @angular in node_modules and into that @angular there has to be a folder named core

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.