gpt4 book ai didi

angular - 模块 'MyCustomModule' 导入的意外值 'AppModule'

转载 作者:太空狗 更新时间:2023-10-29 16:50:19 25 4
gpt4 key购买 nike

我正在尝试将我的一个 angular2 自定义库迁移到 RC.6 + Webpack。我的目录结构是:

- src - source TS files
- lib - transpiled JS files + definition files
- dev - development app to test if it works / looks ok.
- myCustomLib.js - barrel
- myCustomLib.d.ts

dev 文件夹中尝试运行一个应用程序。我引导我的模块:

app.module.ts

import { BrowserModule }                from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import { MyCustomModule } from "../../myCustomLib";

@NgModule({
imports: [
BrowserModule,
MyCustomModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
}

现在我使用 webpack 捆绑了我的开发应用程序。

webpack.config.js

module.exports = {
entry: "./app/boot",
output: {
path: __dirname,
filename: "./bundle.js",
},
resolve: {
extensions: ['', '.js', '.ts'],
modules: [
'node_modules'
]
},
devtool: 'source-map',
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}, {
test: /\.ts$/,
loader: 'awesome-typescript-loader',
exclude: /node_modules/
}]
},
watch: true
};

但是当我尝试加载应用程序时,我收到一条消息:

metadata_resolver.js:230
Uncaught Error: Unexpected value 'MyCustomModule' imported by the module 'AppModule'

我导入的桶文件如下所示:

myCustomLib.js

export * from './lib/myCustomLib.module';

我还找到了hint on similar topic on github , 但将其更改为:

export { MyCustomModule } from './lib/myCustomLib.module';

没有帮助。我还尝试从 src 目录导入模块 - 同样的错误。 MyCustomModule 应该没问题,因为它之前在 systemJS 上运行良好。

myCustomLib.module.ts:

import { NgModule }                     from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
imports: [
BrowserModule
]
})
export class MyCustomModule {}

知道这个错误的原因是什么吗?我在这里看到过类似的主题,但没有任何答案或提示有帮助。

编辑:为了使示例更加简单,我从 MyCustomModule 中删除了所有内容 - 同样的问题...

最佳答案

myCustomLib.js 中,尝试先导入再导出

import { MyCustomModule } from './lib/myCustomLib.module;

export MyCustomModule;

关于angular - 模块 'MyCustomModule' 导入的意外值 'AppModule',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39385191/

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