[英]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.