1

我一直在尝试使用 ng2-eonasdan-datetimepicker,但运气不佳。这是正在发生的事情:

Z:\Dashboard>npm start

> dashboard@0.0.0 start Z:\Dashboard
> ng serve

** NG Live Development Server is running on http://localhost:4200 **
Hash: 8c10d4427bac000e3cf8
Time: 14549ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 158 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 206 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 37.4 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 5.28 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

ERROR in A2Edatetimepicker is not an NgModule
webpack: Failed to compile.

然后我打开项目中的任何文件,不更改代码,只需在某处放置一个空格并保存,以便重新编译,它就可以工作了!但它不会ng build。当我尝试构建项目时,出现此错误:

ERROR in Unexpected value 'A2Edatetimepicker in Z:/Dashboard/node_modules/ng2-eonasdan-datetimepicker/dist/datetimepicker.module.d.ts' imported by the module 'AppModule in Z:/Dashboard/src/app/app.module.ts'. Please add a @NgModule annotation.

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'Z:\Dashboard\src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

在我的日历组件中:

import * as datetimepicker from 'eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js';

和我的 app.module.ts:

import { A2Edatetimepicker } from 'ng2-eonasdan-datetimepicker/dist/datetimepicker.module';

imports: [
  A2Edatetimepicker
]

这就是它的要点。有人知道我在做什么错吗?

测试 1 更改:

import { A2Edatetimepicker } from 'ng2-eonasdan-datetimepicker/dist/datetimepicker.module';
to
import { A2Edatetimepicker } from 'ng2-eonasdan-datetimepicker';

新错误:

ERROR in Error encountered resolving symbol values statically. Calling function 'makeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol Injectable in Z:/Dashboard/node_modules/ng2-eonasdan-datetimepicker/node_modules/@angular/core/src/di/metadata.d.ts, resolving symbol OpaqueToken in Z:/Dashboard/node_modules/ng2-eonasdan-datetimepicker/node_modules/@angular/core/src/di/opaque_token.d.ts, resolving symbol OpaqueToken in Z:/Dashboard/node_modules/ng2-eonasdan-datetimepicker/node_modules/@angular/core/src/di/opaque_token.d.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'Z:\Dashboard\src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

新信息:

我发现如果我使用ng build --prod --aot false我会得到一个不同的错误:

ERROR in A2Edatetimepicker is not an NgModule

未找到解决方案,但这暂时有效......我改变了:

import { A2Edatetimepicker } from 'ng2-eonasdan-datetimepicker/dist/datetimepicker.module';

imports: [
  A2Edatetimepicker
]
to

import { DateTimePickerDirective } from 'ng2-eonasdan-datetimepicker/dist/datetimepicker.directive.js';

declarations: [
  DateTimePickerDirective
]

它有效,但仅适用于ng build --prod --aot false. 不过,我认为这对最终构建不起作用。至少我现在可以继续努力。但这个问题肯定仍然存在。当我使用时,ng build --prod我仍然收到上面的错误:

ERROR in Error encountered resolving symbol values statically. Calling function 'makeDecorator'...........

有人知道怎么修这个东西吗?

4

0 回答 0