Reputation: 1686
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
Upvotes: 2
Views: 28455
Reputation: 3754
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.
Upvotes: 1
Reputation: 837
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
Upvotes: 1
Reputation: 2370
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.
Upvotes: 5
Reputation: 1686
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.
Upvotes: 2
Reputation: 318
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.
Upvotes: 1
Reputation: 2950
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
Upvotes: 0