簡體   English   中英

tsc編譯導入路徑錯誤,在@ angular / material的末尾添加索引

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM