Я думаю, что это проблема с WebStorm, а не с центральной проблемой Angular. Вот как он импортируется, когда я нажимаю Alt + Enter, а затем, когда я открываю веб-страницу, он говорит 404 для этого node_module
.Почему Angular 2 импортирует из относительных node_modules вместо сопоставленных node_modules?
import {Router} from "../../../../node_modules/@angular/router/src/router";
import {ActivatedRoute} from "../../../../node_modules/@angular/router/src/router_state";
Прежде чем использовать для импорта, как это, который является правильным:
import {Router, ActivatedRoute} from "@angular/router";
Он привык работать нормально, но теперь это не импорт из отображенных файлов в system.config.js
. Я не знаю, почему это произошло. Я попытался изменить diff вещи в system.config.js
и tsconfig.json
. Не знаю, связано ли это с этим.
Мои System.config.js:
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/platform-server': 'npm:@angular/platform-server/bundles/platform-server.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'ng2-translate/ng2-translate': 'npm:ng2-translate/bundles/ng2-translate.umd.js',
'ng2-translate': 'npm:ng2-translate/bundles/ng2-translate.umd.js',
'primeng': 'npm:primeng'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
primeng: {
defaultExtension: 'js'
},
}
});
})(this);
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"removeComments": false,
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"node_modules",
"typings",
"aot"
]
}
необходимо скриншот с файлом File | Настройки | Редактор | Общий | Авто импорт страницы – lena
Я добавил sdreenshot. –
, какую версию вы используете? Какую версию «@ угловой/роутер» вы используете? Убедитесь, что существует файл "node_modules/@angular/router/index.d.ts" – anstarovoyt