digitransit-ui icon indicating copy to clipboard operation
digitransit-ui copied to clipboard

Cannot provide node options and run start

Open shriharip opened this issue 8 years ago • 3 comments

When I run API_URL=https://api.digitransit.fi GEOCODING_BASE_URL=https://api.digitransit.fi/geocoding/v1 OTP_URL=https://api.digitransit.fi/routing/v1/routers/finland/ yarn run start

I get module error a node_error

As you can see I just created a simple stats.json file but it does not work

In app/server.js when the environment is not dev it looks for manifest and stats json file

if (process.env.NODE_ENV !== 'development') { // eslint-disable-next-line global-require, import/no-unresolved assets = require('../manifest.json'); // eslint-disable-next-line global-require, import/no-unresolved mainAssets = require('../stats.json').entrypoints.main.assets.filter( asset => !asset.endsWith('.map'), );

How should we provide it? Thanks

shriharip avatar Nov 29 '18 14:11 shriharip

If I understood the problem correctly, you have the option to let webpack generate the stats.json file by running the command yarn run build prior to starting the server in production mode.

jolkkola avatar Dec 03 '18 07:12 jolkkola

I can confirm this is still happening as of the most recent available version in 2020. The app works perfectly with yarn run dev, but does not work with yarn run build and then yarn run start.

I have tried creating blank JSONs ({}) with the names stats.json and manifest.json. It was complaining about missing properties. I have then tried commenting the lines regarding manifestFiles and mainAssets in app/server.js, but after that when running yarn run start and accessing the webpage, it throws an Unhandled Rejection at: Promise with the following exception:

<rejected> TypeError: Cannot read property 'map' of undefined
      at /root/digitransit-ui/app/server.js:296:23
      at /root/digitransit-ui/node_modules/react-router/lib/match.js:67:5
      at /root/digitransit-ui/node_modules/react-router/lib/createTransitionManager.js:108:11
      at done (/root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:79:19)
      at /root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:85:7
      at getComponentsForRoute (/root/digitransit-ui/node_modules/react-router/lib/getComponents.js:11:5)
      at /root/digitransit-ui/node_modules/react-router/lib/getComponents.js:35:5
      at /root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:84:5
      at Array.forEach (<anonymous>)
      at mapAsync (/root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:83:9) } reason: TypeError: Cannot read property 'map' of undefined
    at /root/digitransit-ui/app/server.js:296:23
    at /root/digitransit-ui/node_modules/react-router/lib/match.js:67:5
    at /root/digitransit-ui/node_modules/react-router/lib/createTransitionManager.js:108:11
    at done (/root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:79:19)
    at /root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:85:7
    at getComponentsForRoute (/root/digitransit-ui/node_modules/react-router/lib/getComponents.js:11:5)
    at /root/digitransit-ui/node_modules/react-router/lib/getComponents.js:35:5
    at /root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:84:5
    at Array.forEach (<anonymous>)
    at mapAsync (/root/digitransit-ui/node_modules/react-router/lib/AsyncUtils.js:83:9)

The documentation available at https://github.com/HSLdevcom/digitransit-ui/blob/master/docs/Installation.md does not help me clear this issue.

For now my only option is just running with dev enabled.

BodoMinea avatar Apr 12 '20 21:04 BodoMinea

I faced the same problem when building the docker image for the app. Here are my findings. During the build, an error occurs, without stopping the build process:

^[[0m^[[91m<s> [webpack.Progress] 10% building 3/23 modules 20 active /opt/digitransit-ui/node_modules/mini-css-extract-plugin/dist/loader.js!/opt/digitransit-ui/node_modules/css-loader/dist/cjs.js!/opt/digitransit-ui/node_modules/postcss-loader/src/index.js!/opt/digitransit-ui/node_modules/sass-loader/dist/cjs.js!/opt/digitransit-ui/sass/themes/turku/main.scss
^[[0m^[[91m(node:1422) UnhandledPromiseRejectionWarning: Error: spawn ENOMEM
    at ChildProcess.spawn (internal/child_process.js:366:11)
    at spawn (child_process.js:551:9)
    at Object.fork (child_process.js:113:10)
    at ChildProcessWorker.initialize (/opt/digitransit-ui/node_modules/jest-worker/build/workers/ChildProcessWorker.js:137:44)
    at new ChildProcessWorker (/opt/digitransit-ui/node_modules/jest-worker/build/workers/ChildProcessWorker.js:127:10)
    at WorkerPool.createWorker (/opt/digitransit-ui/node_modules/jest-worker/build/WorkerPool.js:44:12)
    at new BaseWorkerPool (/opt/digitransit-ui/node_modules/jest-worker/build/base/BaseWorkerPool.js:82:27)
    at new WorkerPool (/opt/digitransit-ui/node_modules/jest-worker/build/WorkerPool.js:30:1)
    at new JestWorker (/opt/digitransit-ui/node_modules/jest-worker/build/index.js:131:26)
    at TaskRunner.run (/opt/digitransit-ui/node_modules/terser-webpack-plugin/dist/TaskRunner.js:45:21)
    at TerserPlugin.optimizeFn (/opt/digitransit-ui/node_modules/terser-webpack-plugin/dist/index.js:308:47)
    at _next1 (eval at create (/opt/digitransit-ui/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:17)
    at _promise1.then._result1 (eval at create (/opt/digitransit-ui/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:28:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)
^[[0m^[[91m(node:1422) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:1422) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^[[0m^[[91m<s> [webpack.Progress] 10% building 3/24 modules 21 active /opt/digitransit-ui/node_modules/intl/locale-data/jsonp lazy-once /^.\/(fi|sv|en|fr|nb|de|pt)$/ groupOptions: {} namespace object

Because of that, the build process stops "successfully" at around 70%:

<s> [webpack.Progress] 69% building 2114/2115 modules 1 active css /opt/digitransit-ui/node_modules/css-loader/dist/cjs.js!/opt/digitransit-ui/node_modules/postcss-loader/src/index.js!/opt/digitransit-ui/node_modules/sass-loader/dist/cjs.js!/opt/digitransit-ui/sass/themes/turku/main.scss 0
<s> [webpack.Progress] 70% building 2115/2115 modules 0 active
<s> [webpack.Progress] 70% building 2115/2115 modules 0 active
^[[0mDone in 164.25s.
yarn cache v1.22.4
success Cleared cache.
Done in 7.58s.
Removing intermediate container 98202ccf977c
 ---> d70ad9870e67
Step 8/8 : CMD yarn run start
 ---> Running in 91d7a0b51d0c
Removing intermediate container 91d7a0b51d0c
 ---> 1074fc7b41a2
Successfully built 1074fc7b41a2
Successfully tagged digitransit2_digitransit-ui:latest

My lack of experience building node applications lead me to ignore that. And so, the manifest.json file was not created (@BodoMinea, as far as i know this is not a file you can create 'by hand' ).

Anyway, googling around the error, the results lead to a possible memory leak. But the odd thing is that i was able to build the image successfully on my macbook, but not on a centos 7 + docker.

Update: after updating docker, the error was gone! Update 2: my initial issue was, in fact, lack of free memory (updating docker caused some memory to be freed, making the build process to work). Strangely, docker itself didn't complain (usually in these situations, it raises some error like "command failed with exit code 137"

jaimeventura avatar Jun 18 '20 08:06 jaimeventura