[英]tsc compile import with wrong path, adding index at the end of @angular/material
我正在嘗試建立一個庫,以便在多個項目之間聚合和分配一組角度組件,並依賴於angular / material2 。 我的目標是在npm中發布它。
運行tsc
打包lib, .js
文件時遇到問題,嘗試from '@angular/material/index'
導入。 from '@angular/material'
導入相同的文件.d.ts
,但我不知道這種差異來自何處。
我的吞咽:
import {main as tsc} from '@angular/tsc-wrapped';
const libraryRoot = join('/../myproject/src', 'lib');
const tsconfigPath = join(libraryRoot, 'tsconfig.json');
task('library:build:esm', () => tsc(tsconfigPath, {basePath: libraryRoot}));
我的tsconfig:
{
"compilerOptions": {
"baseUrl": ".",
"declaration": false,
"stripInternal": false,
"experimentalDecorators": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../dist/packages/mila-angular",
"paths": {},
"rootDir": ".",
"sourceMap": true,
"inlineSources": true,
"target": "es2015",
"lib": ["es2015", "dom"],
"skipLibCheck": false,
"types": [
]
},
"files": [
"public-api.ts",
"typings.d.ts"
],
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"flatModuleOutFile": "index.js",
"flatModuleId": "mila-angular",
"skipTemplateCodegen": true
}
}
myComponent.ts
import { MdDialog, MdDialogRef } from '@angular/material';
myComponent.d.ts
import { MdDialog, MdDialogRef } from '@angular/material';
myComponent.js
import { MdDialog, MdDialogRef } from '@angular/material/index';
結果,在導入我的庫時,出現以下錯誤消息:
import { ButtonModule } from 'myLibrary';
ERROR in ./~/myLibrary/myLibrary.es5.js
Module not found: Error: Can't resolve '@angular/material/index' in '/.../myProject/node_modules/myLibrary'
@ ./~/myLibrary/myLibrary.es5.js 8:0-80
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
webpack: Failed to compile.
如果我手動編輯myLibrary.es5.js
並刪除/index
一切正常。
(@ angular / material buildind進程非常重視所有過程)
好的,發現了我的問題,但是出於未知的原因,npm確實使用完整代碼而不是已構建的版本安裝了@angular/material
。 我擁有所有的.ts
文件和index.ts
所以我想tsc確實使用了它。
解決了它,我們刪除了node_modules
文件夾並再次運行npm i
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.