Ionic3项目可以serve但是build会报错大概是什么原因?

Ice丶Wing
  • 407

一个angular-ionic开发的项目,用ionic serve命令运行没有任何问题,但是一旦想用ionic build --prod命令打包就开始报错。这种情况一般都是由于什么原因引起的?有没有大佬指点一下。

报错的内容:

[09:26:18] ionic-app-script task: "build"
[09:26:18] Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused

        by using 'barrel' index.ts files.

Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.

at syntaxError (E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:1550:34)
at E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:14936:40
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:14921:19)
at CompileMetadataResolver.getNgModuleMetadata (E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:14576:50)
at addNgModule (E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:23050:58)
at E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:23061:14
at Array.forEach (<anonymous>)
at _createNgModules (E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:23060:26)
at analyzeNgModules (E:\abcd\node_modules\@angular\compiler\bundles\compiler.umd.js:22935:14)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ionic-hello-world@0.0.0 ionic:build: ionic-app-scripts build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ionic-hello-world@0.0.0 ionic:build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

检查了所有的module,并没有出现循环依赖。不过项目在最近改用了Ionic3的懒加载重新弄了路由,不知道是不是和这个有点关系

回复
阅读 3.3k
2 个回答

ionic3和2的结构差别还是挺大,单单针对你的这个错误,有可能是你的服务和模块声明在同一个文件,并且服务优先于模块声明。

你的第一个错误是,你没有在app.modules.ts中引入barrel这个provider

宣传栏