【问题标题】:Cannot find module 'md5' on Importing vendorNpmFile ts-md5在导入 vendorNpmFile ts-md5 时找不到模块“md5”
【发布时间】:2019-04-01 13:40:50
【问题描述】:

可能与 Ref 重复:Angular2 - Angular-CLI installing lodash - Cannot find module 但对我不起作用

跟随https://github.com/angular/angular-cli/wiki/3rd-party-libs使用https://www.npmjs.com/package/ts-md5导入ts-md

在 node_modules 上使用 npm install ts-md5 --save 导入 ts-md5。我在 angular-cli 设置中的配置是

package.json:

"devDependencies": {
  ......
  "ts-md5": "^1.2.0"
}

anular-cli-build 配置:

 var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
 var mergeTree = require('broccoli-merge-trees');
 module.exports = function(defaults) {
 let appTree = new Angular2App(defaults, {
 sassCompiler: {
  cacheExclude: [/\/_[^\/]+$/]
 },
 vendorNpmFiles: [
   ....
  'ts-md5/dist/md5.js'
 ]
 })
 return mergeTree([appTree], { overwrite: true });
 };

在 ng build 我可以找到在 vendor/ts-md5/dist/md5.js 中导入的 md5 文件

系统配置.ts:

const map: any = {
  'moment' : 'vendor/moment/moment.js',
  'ng2-bootstrap' : 'vendor/ng2-bootstrap',
  '@angular2-material': 'vendor/@angular2-material',
  'd3' : 'vendor/d3',
  'md5': 'vendor/ts-md5/dist/md5.js'
};

/** User packages configuration. */
const packages: any = {
  'moment' : {
    format: 'cjs'
  },
  'ng2-bootstrap' : {   
    defaultExtension: 'js'
  },
  'd3' : {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'd3.min.js'
  },
  'md5': {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'md5.js'
  }
};

在我的公司中包含 import * as md5 from 'md5' 以导入 ts-md5。

在 ng build 时,我无法找到模块 'md5'

Error: Typescript found the following errors:
GitRepo/app-web/tmp/broccoli_type_script_compiler-input_base_path-zurkjkU9.tmp/0/src/app/shared/gravatar/gravatar.component.ts (3, 22): Cannot find module 'md5'.
at BroccoliTypeScriptCompiler._doIncrementalBuild (/GitRepo/app-web/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:120:19)
at BroccoliTypeScriptCompiler.build (/GitRepo/app-web/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:43:10)
at /GitRepo/app-web/node_modules/angular-cli/node_modules/broccoli-caching-writer/index.js:152:21

对此的任何帮助都会很棒。

【问题讨论】:

    标签: angular angular-cli


    【解决方案1】:

    安装此模块。

    npm install ts-md5 --save
    

    【讨论】:

      【解决方案2】:

      在你的 typings.d.ts 中添加这个

      declare module 'md5' { var exportAs:any; export = exportAs; }

      【讨论】:

      • Getting Module ''md5'' 对于大多数 npm md5 包没有导出的 mng 'md5'
      猜你喜欢
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-15
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      相关资源
      最近更新 更多