在 Linux 上使用 Angular4 构建 JHipster 时的问题
Posted
技术标签:
【中文标题】在 Linux 上使用 Angular4 构建 JHipster 时的问题【英文标题】:Issue when building JHipster with Angular4 on Linux 【发布时间】:2017-11-13 09:19:38 【问题描述】:我正在尝试使用 Jenkins 在服务器端构建我的应用程序。运行命令时: **sudo ./mvnw -Pprod 包* 我收到以下错误消息:
[INFO] --- frontend-maven-plugin:1.6:yarn (webpack build prod) @ timetrack ---
[INFO] Running 'yarn run webpack:prod' in /var/lib/jenkins/workspace/timetrack-jh
[INFO] yarn run v1.2.1
[INFO] $ yarn run cleanup && yarn run webpack:prod:main && yarn run clean-www
[ERROR] warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
[ERROR] module.js:471
[ERROR] throw err;
[ERROR] ^
[ERROR]
[ERROR] Error: Cannot find module '/var/lib/jenkins/workspace/timetrack-jh/webpack/webpack.prod.js'
[ERROR] at Function.Module._resolveFilename (module.js:469:15)
[ERROR] at Function.Module._load (module.js:417:25)
[ERROR] at Module.require (module.js:497:17)
[ERROR] at require (internal/module.js:20:19)
[ERROR] at requireConfig (/var/lib/jenkins/workspace/timetrack-jh/node_modules/webpack/bin/convert-argv.js:97:18)
[ERROR] at /var/lib/jenkins/workspace/timetrack-jh/node_modules/webpack/bin/convert-argv.js:104:17
[ERROR] at Array.forEach (native)
[ERROR] at module.exports (/var/lib/jenkins/workspace/timetrack-jh/node_modules/webpack/bin/convert-argv.js:102:15)
[ERROR] at yargs.parse (/var/lib/jenkins/workspace/timetrack-jh/node_modules/webpack/bin/webpack.js:171:41)
[ERROR] at Object.Yargs.self.parse (/var/lib/jenkins/workspace/timetrack-jh/node_modules/webpack/node_modules/yargs/yargs.js:533:18)
[ERROR] error Command failed with exit code 1.
[ERROR] error Command failed with exit code 1.
[ERROR] error Command failed with exit code 1.
[INFO] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------*
我在我的 Windows 机器上完成了相同的构建,并且工作正常。有人可以帮助我了解 Linux 系统上发生了什么吗?
Linux 版本:Linux 版本 4.10.0-37-generic (buildd@lgw01-amd64-022) (gcc 版本 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2)) #41-Ubuntu SMP Fri Oct 6 20: 2017 年世界标准时间 20:00
提前致谢,
-棒
经过一番处理,我解决了上述问题,但仍然出现新的错误消息(仅在 Linux 上,Windows 运行良好):
[INFO] Installed Yarn locally.
[INFO]
[INFO] --- frontend-maven-plugin:1.6:yarn (yarn install) @ timetrack ---
[INFO] Running 'yarn install' in /home/rodrigo/test/TimeTrack
[INFO] yarn install v1.2.1
[INFO] [1/5] Validating package.json...
[INFO] [2/5] Resolving packages...
[INFO] [3/5] Fetching packages...
[INFO] info fsevents@1.1.2: The platform "linux" is incompatible with this modul e.
[INFO] info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[INFO] [4/5] Linking dependencies...
[ERROR] warning "bootstrap@4.0.0-beta" has unmet peer dependency "popper.js@^1.1 1.0".
[ERROR] warning "@schematics/angular@0.0.49" has incorrect peer dependency "@ang ular-devkit/schematics@0.0.34".
[ERROR] warning "license-webpack-plugin@1.1.1" has unmet peer dependency "webpac k-sources@>=1.0.0".
[INFO] [5/5] Building fresh packages...
[INFO] Done in 40.25s.
[INFO]
[INFO] --- frontend-maven-plugin:1.6:yarn (webpack build prod) @ timetrack ---
[INFO] Running 'yarn run webpack:prod' in /home/rodrigo/test/TimeTrack
[INFO] yarn run v1.2.1
[INFO] $ yarn run cleanup && yarn run webpack:prod:main && yarn run clean-www
[ERROR] warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
[INFO]
[INFO] <--- Last few GCs --->
[INFO]
[INFO] 28 ms: Mark-sweep 1.4 (5.5) -> 1.3 (5.5) MB, 1.2 / 0.0 ms [allocati on failure] [GC in old space requested].
[INFO] 29 ms: Mark-sweep 1.3 (5.5) -> 1.3 (5.5) MB, 1.2 / 0.0 ms [allocati on failure] [GC in old space requested].
[INFO] 30 ms: Mark-sweep 1.3 (5.5) -> 1.3 (5.5) MB, 1.2 / 0.0 ms [allocati on failure] [GC in old space requested].
[INFO] 32 ms: Mark-sweep 1.3 (5.5) -> 1.3 (4.5) MB, 1.2 / 0.0 ms [last res ort gc].
[INFO] 33 ms: Mark-sweep 1.3 (4.5) -> 1.3 (4.5) MB, 1.2 / 0.0 ms [last res ort gc].
[INFO]
[INFO]
[INFO] <--- JS stacktrace --->
[INFO]
[INFO] ==== JS stack trace =========================================
[INFO]
[INFO] Security context: 0x3957b609 <JS Object>
[INFO] 1: /* anonymous */(aka /* anonymous */) [fs.js:10] [pc=0x29d1d25d] (t his=0x395081d9 <undefined>,exports=0x3d777f45 <an Object with map 0x4e409cad>,re quire=0x39585bf1 <JS Function NativeModule.require (SharedFunctionInfo 0x3958425 d)>,module=0x3d777f11 <a NativeModule with map 0x4e40e2a1>,__filename=0x3d777f31 <String[5]: fs.js>,__dirname=0x395081d9 <undefined>)
[INFO] 2: arguments adaptor frame: 4-...
[INFO]
[ERROR] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - javascript heap out of memory
[ERROR] 1: node::Abort() [node]
[ERROR] 2: 0x8c80076 [node]
[ERROR] 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
[ERROR] 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
[ERROR] 5: v8::internal::Factory::NewMap(v8::internal::InstanceType, int, v8::i nternal::ElementsKind) [node]
[ERROR] 6: v8::internal::Map::RawCopy(v8::internal::Handle<v8::internal::Map>, int) [node]
[ERROR] 7: v8::internal::Map::CopyDropDescriptors(v8::internal::Handle<v8::inte rnal::Map>) [node]
[ERROR] 8: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::i nternal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal ::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::inte rnal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransiti onFlag) [node]
[ERROR] 9: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::intern al::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
[ERROR] 10: v8::internal::Map::CopyWithConstant(v8::internal::Handle<v8::interna l::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::inte rnal::Object>, v8::internal::PropertyAttributes, v8::internal::TransitionFlag) [ node]
[ERROR] 11: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8: :internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle< v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::S toreFromKeyed) [node]
[ERROR] 12: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::in ternal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Objec t>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [nod e]
[ERROR] 13: v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v 8::internal::Object::ShouldThrow, v8::internal::Object::StoreFromKeyed) [node]
[ERROR] 14: v8::internal::JSObject::AddProperty(v8::internal::Handle<v8::interna l::JSObject>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8: :internal::Object>, v8::internal::PropertyAttributes) [node]
[ERROR] 15: v8::internal::Factory::NewFunction(v8::internal::Handle<v8::internal ::String>, v8::internal::Handle<v8::internal::Code>, v8::internal::Handle<v8::in ternal::Object>, v8::internal::InstanceType, int, bool, bool, bool) [node]
[ERROR] 16: v8::internal::ApiNatives::CreateApiFunction(v8::internal::Isolate*, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v 8::internal::Object>, v8::internal::ApiNatives::ApiInstanceType) [node]
[ERROR] 17: 0x8554502 [node]
[ERROR] 18: v8::internal::ApiNatives::InstantiateFunction(v8::internal::Handle<v 8::internal::FunctionTemplateInfo>) [node]
[ERROR] 19: v8::FunctionTemplate::GetFunction(v8::Local<v8::Context>) [node]
[ERROR] 20: v8::FunctionTemplate::GetFunction() [node]
[ERROR] 21: node::InitFs(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local< v8::Context>, void*) [node]
[ERROR] 22: 0x8c858a0 [node]
[ERROR] 23: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionC allbackInfo<v8::Value> const&)) [node]
[ERROR] 24: 0x85b3630 [node]
[ERROR] 25: 0x85b3dd0 [node]
[ERROR] 26: 0x4890a0fe
[ERROR] 27: 0x29d1d25d
[ERROR] 28: 0x4890b616
[ERROR] 29: 0x489384a8
[ERROR] 30: 0x48937d7f
[ERROR] 31: 0x29d1b14f
[ERROR] 32: 0x4890b616
[ERROR] 33: 0x489384a8
[ERROR] 34: 0x48937d7f
[ERROR] 35: 0x48937411
[ERROR] 36: 0x48936335
[ERROR] 37: 0x4893153e
[ERROR] 38: 0x48920a43
[ERROR] 39: v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal:: Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v 8::internal::Handle<v8::internal::Object>*) [node]
[ERROR] 40: v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int , v8::Local<v8::Value>*) [node]
[ERROR] 41: v8::Function::Call(v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [node]
[ERROR] 42: node::LoadEnvironment(node::Environment*) [node]
[ERROR] 43: node::Start(int, char**) [node]
[ERROR] 44: main [node]
[ERROR] 45: __libc_start_main [/lib/i386-linux-gnu/libc.so.6]
[ERROR] Aborted (core dumped)
[ERROR] error Command failed with exit code 134.
[ERROR] error Command failed with exit code 1.
[ERROR] error Command failed with exit code 1.
[INFO] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about th is command.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:09 min
[INFO] Finished at: 2017-11-14T19:58:35+13:00
[INFO] Final Memory: 31M/74M
[INFO] ------------------------------------------------------------------------
有人帮忙吗?
问候,
-棒
【问题讨论】:
不应要求使用 sudo ,这很危险。你检查过 /var/lib/jenkins/workspace/timetrack-jh/webpack/webpack.prod.js 真的不存在吗? 嗨,盖尔。不,目录 ../webpack 不存在。 所以要么在项目生成过程中出现问题,要么您没有将所有文件提交到 git。与示例应用比较:github.com/jhipster/jhipster-sample-app-ng2 问题依然存在。现在又回到了最初的Javascript堆内存不足的问题。 【参考方案1】:我再次发现了这个问题。在 Linux 机器上构建并且 Javascript 上的堆内存不足时。需要更改 package.json 上的那些行(仅在使用 JHipster 和 Angular 4 时发生):
"webpack-dev-server": "node --max_old_space_size=5120 node_modules/webpack-dev-server/bin/webpack-dev-server.js", "webpack": "node --max_old_space_size=5120 node_modules/webpack/bin/webpack.js"
我将 --max_old_space_size 从 4096 更新为 5120(多 1GB)。
就是这样!
感谢帮助我的好人,
最好的问候,
-棒
【讨论】:
以上是关于在 Linux 上使用 Angular4 构建 JHipster 时的问题的主要内容,如果未能解决你的问题,请参考以下文章
在 Heroku 上构建 Angular 4 应用程序时,不包括资产
利用angular4和nodejs-express构建一个简单的网站—用户登录
在 Heroku 上使用 Django Rest Framework 后端部署 Angular 4 前端