相对路径。baseUrl和路径不适用于ionic2-angular2
我一直在读类似的堆栈溢出,但我还没有弄明白。我一定错过了一小步 我的目标是能够做到:相对路径。baseUrl和路径不适用于ionic2-angular2,angular,typescript,ionic2,typing,Angular,Typescript,Ionic2,Typing,我一直在读类似的堆栈溢出,但我还没有弄明白。我一定错过了一小步 我的目标是能够做到: import { Logger } from 'logging' 而不是 import { Logger } from '../../modules/logging' 我的tsconfig如下所示: { "compilerOptions": { "allowSyntheticDefaultImports": true, "declaration": false, "emitDec
import { Logger } from 'logging'
而不是
import { Logger } from '../../modules/logging'
我的tsconfig如下所示:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"baseUrl": ".",
"paths":{
"*":[
"src/app/*",
"node_modules/*"
]
}
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
我的文件夹结构类似于
src
--- app
------- logging
--------------- index.ts (contains exports for the provider and the ngModule)
--------------- logger.provider.ts (contains an injectable provider)
--------------- logging.module.ts (contains the ngModule)
--- app.module.ts
该指数基本上有以下特点:
export { LoggingModule } from './logging.module';
export { LoggerProvider } from './logger.provider';
当然,我省略了结构中的文件。app.module.ts是我尝试导入“日志记录”模块的入门类。Visual Studio代码不会抱怨我的导入
//import { FIREBASE_CONFIG } from 'configs';
import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { AngularFireModule } from "angularfire2";
import { LoggingModule } from 'logging';
import { PostsModule } from 'posts';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
IonicModule.forRoot(MyApp),
PostsModule,
LoggingModule
//AngularFireModule.initializeApp(FIREBASE_CONFIG),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}
正如我所说,VSC没有显示任何错误,但当我在浏览器中启动应用程序时,我得到:
Error: Cannot find module "logging"
at Object.<anonymous> (http://localhost:8100/build/main.js:82202:7)
at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
at Object.<anonymous> (http://localhost:8100/build/main.js:105047:70)
at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
at http://localhost:8100/build/main.js:66:18
at http://localhost:8100/build/main.js:69:10
错误:找不到模块“日志记录”
反对。(http://localhost:8100/build/main.js:82202:7)
在需要的网页上(http://localhost:8100/build/main.js:20:30)
反对。(http://localhost:8100/build/main.js:105047:70)
在需要的网页上(http://localhost:8100/build/main.js:20:30)
在http://localhost:8100/build/main.js:66:18
在http://localhost:8100/build/main.js:69:10
我真的不想回到漫长的相对路线上来,因为1)这很乏味,2)当应用程序增长时,重构会成为一场噩梦
谢谢 我怀疑设置为
节点的moduleResolution
可能是问题的原因。将其更改为classic
,然后查看是否已解决
"compilerOptions": {
"moduleResolution": "classic"
看看这个。希望它能解决错误。据我所知,如果您从同一个项目导入自己的模块,则需要使用相对url。如果是从npm安装的,我只导入了相对url,而npm将是您的package.json
中列出的模块。请在app
Hi中尝试tsc--traceResolution
。谢谢我自己没有添加,这是爱奥尼亚设置的一部分。问题是把它改成经典会破坏一切。ie:找不到名称“Observable”,找不到名称“AngularFireDatabase”,等等。路径不包括节点\模块文件夹吗?