首页 > 解决方案 > Symfony 5.2 + Webpack Encore:npm 运行显示错误“意外令牌”

问题描述

我已经设置了一个新项目,并在没有 root 访问权限的共享服务器Symfony 5.2上添加了 Webpack Encore 。

Yarn 在这台机器上不可用,所以我使用了 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

webpack.config.js我没有对自动创建的和asset/文件进行任何更改。运行npm run dev导致Unexpected token错误:

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

由于我的任何自定义文件中都没有报告错误,我认为这是 Node.js / Webpack 本身的问题?这个对吗?

消息说,应该使用最新版本的 node.js 和 npm。服务器上可用的版本(节点 v6.11.3 和 npm v3.10.10)确实很旧,但没有 root 访问权限我无法更改它,可以吗?

但是,由于使用这些 node.js 和 npm 版本添加/安装 Webpack Encore 没有任何问题,我想知道使用这些旧版本是否真的是问题的原因。

我能做些什么来找到真正的原因并解决问题吗?


// /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 ]

标签: node.jssymfonynpmwebpack

解决方案


推荐阅读