[英]tsc compile import with wrong path, adding index at the end of @angular/material
I am trying to buiding a library to agregate and distribute a set of angular components between multiple projects, with a dependancy on angular/material2 . 我正在尝试建立一个库,以便在多个项目之间聚合和分配一组角度组件,并依赖于angular / material2 。 My goal is to publish it in npm.
我的目标是在npm中发布它。
Having an issue when running tsc
to package the lib, .js
file try to import from '@angular/material/index'
. 运行
tsc
打包lib, .js
文件时遇到问题,尝试from '@angular/material/index'
导入。 Same file .d.ts
import from '@angular/material'
and I do not understand where this difference is coming from. from '@angular/material'
导入相同的文件.d.ts
,但我不知道这种差异来自何处。
My gulp : 我的吞咽:
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}));
My tsconfig : 我的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 myComponent.ts
import { MdDialog, MdDialogRef } from '@angular/material';
myComponent.d.ts myComponent.d.ts
import { MdDialog, MdDialogRef } from '@angular/material';
myComponent.js myComponent.js
import { MdDialog, MdDialogRef } from '@angular/material/index';
As a result, when importing my library I have the following error message : 结果,在导入我的库时,出现以下错误消息:
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.
If i manually edit myLibrary.es5.js
and remove /index
everything works fine. 如果我手动编辑
myLibrary.es5.js
并删除/index
一切正常。
(All process is highly inspried by @angular/material buildind process) (@ angular / material buildind进程非常重视所有过程)
All right, found my problem but for un unknown reason npm did install @angular/material
with full code instead of builded version. 好的,发现了我的问题,但是出于未知的原因,npm确实使用完整代码而不是已构建的版本安装了
@angular/material
。 I was having all .ts
files and index.ts
so I guess tsc did natuarlly used it. 我拥有所有的
.ts
文件和index.ts
所以我想tsc确实使用了它。
Solved it we deleting node_modules
folder and running npm i
again. 解决了它,我们删除了
node_modules
文件夹并再次运行npm i
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.