0

I have setup a new Symfony 5.2 project and added Webpack Encore on a shared Server with no root access.

Yarn is not available on this machine, so I used npm:

// setup new Symfony 5.2 project
symfony new sym5 --version=5.2 --full
...
cd sym5

// add Webpack Encore
composer require symfony/webpack-encore-bundle
npm install
...

// try to compile assets
npm run dev

I have made no changes to the webpack.config.js and asset/ files which have been automatically created. Running npm run dev leads to an Unexpected token error:

npm run dev

> @ dev /customers/123/webpages/sym5
> encore dev

/customers/123/webpages/sym5/node_modules/pkg-up/index.js:4
module.exports = async ({cwd} = {}) => findUp('package.json', {cwd});
                       ^

SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/customers/123/webpages/sym5/node_modules/@symfony/webpack-encore/lib/config/parse-runtime.js:13:15)

npm ERR! Linux 3.18.117-pvops-xen-x64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
npm ERR! node v6.11.3
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `encore dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script 'encore dev'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     encore dev
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs 
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls 
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /customers/123/webpages/sym5/npm-debug.log

Since the error is not reported in any my custom files, I assume that this is a problem of Node.js / Webpack itself? Is this correct?

The message says, that one should use the latest versions of node.js and npm. The versions available on the server (node v6.11.3 and npm v3.10.10) are indeed quite old but without root access I cannot change this, can I?

However, since the adding / installing Webpack Encore using these node.js and npm version worked without any problem, I wonder if using these old version is really the cause of the problem.

Is there anything I can do to find the actual cause and to solve the problem?


// /customers/123/webpages/sym5/npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ]
2 info using npm@3.10.10
3 info using node@v6.11.3
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle @~predev: @
6 silly lifecycle @~predev: no script for predev, continuing
7 info lifecycle @~dev: @
8 verbose lifecycle @~dev: unsafe-perm in lifecycle true
9 verbose lifecycle @~dev: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/customers/123/webpages/sym5/node_modules/.bin:/customers/123/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/customers/123/.gem/bin
10 verbose lifecycle @~dev: CWD: /customers/123/webpages/sym5
11 silly lifecycle @~dev: Args: [ '-c', 'encore dev' ]
12 silly lifecycle @~dev: Returned: code: 1  signal: null
13 info lifecycle @~dev: Failed to exec dev script
14 verbose stack Error: @ dev: `encore dev`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:920:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
15 verbose pkgid @
16 verbose cwd /customers/123/webpages/sym5
17 error Linux 3.18.117-pvops-xen-x64
18 error argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
19 error node v6.11.3
20 error npm  v3.10.10
21 error code ELIFECYCLE
22 error @ dev: `encore dev`
22 error Exit status 1
23 error Failed at the @ dev script 'encore dev'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the  package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     encore dev
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
Andrei Herford
  • 17,570
  • 19
  • 91
  • 225
  • I have had errors like this many times before. Updating npm and node always seemed to fix the problem – Thakkie Dec 04 '20 at 08:44
  • Install NPM without root or sudo https://stackoverflow.com/questions/18088372/how-to-npm-install-global-not-as-root – Thakkie Dec 04 '20 at 08:46
  • @Thakkie Thanks, but the linked post describes how to install npm packages globally without root privileges. Not how install npm itself without root. Or am I missing something? To be able to use a different npm version I would still need root privileges, wouldn't I? – Andrei Herford Dec 04 '20 at 08:57
  • Sorry about the wrong link. This link explains how to install node.js without root access. You might need to remove the original node folder from your path once you are done for this to work.https://www.digizol.com/2017/08/nodejs-install-no-root-sudo-permission-linux-centos.html – Thakkie Dec 04 '20 at 09:20

0 Answers0