gpt4 book ai didi

angularjs - 在 Angular4 中-如何添加 lodash 并进行无错误的构建

转载 作者:太空狗 更新时间:2023-10-29 18:13:36 28 4
gpt4 key购买 nike

我正在使用 angular.io 快速启动种子:https://angular.io/docs/ts/latest/guide/setup.html

我正在使用 Angular4 和 typescript JIT

目前我想添加 lodash,这样我就可以在我的组件中使用它,然后执行 npm run build,例如tsc -p src/"并且没有得到任何错误

我的组件:

import { Component } from '@angular/core';
import * as _ from 'lodash';

@Component({
moduleId: module.id,
selector: 'HomeComponent',
templateUrl: 'home.component.html'
})

export class HomeComponent {

constructor() {
console.log(_.last([1, 2, 3]));
console.log('hello');
}

}

我的 systemjs.config:

/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
'app': 'app',

// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'lodash': 'node_modules/lodash/lodash.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
defaultExtension: 'js',
meta: {
'./*.js': {
loader: 'systemjs-angular-loader.js'
}
}
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);

我在进行构建时遇到以下错误,例如npm run build 但在 npm run serve 上运行正常:

node_modules/@types/lodash/index.d.ts(12847,29): error TS2304: Cannot find name 'object'.
node_modules/@types/lodash/index.d.ts(19587,15): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
node_modules/@types/lodash/index.d.ts(19587,33): error TS2304: Cannot find name 'object'.

最佳答案

您应该将 @types/lodash 降级到版本 4.14.50

我正在使用 lodash4.17.4 版和 angular 2.4.9 版并且具有相同的错误。我在这个 Github thread 中找到了解决方案.

关于angularjs - 在 Angular4 中-如何添加 lodash 并进行无错误的构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43228707/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com