运行 上的 Symfony Webpack encore 错误。再来一次:权限被拒绝

Symfony Webpack encore error on run. encore: Permission denied

带有 webpack encore 的 Symfony 4.1 在 运行 和 npm/yarn

上给出错误

我按照 symfony 官方文档中提到的步骤,在通过 composer require webpack-encore 成功安装后和 npm install 之后,我尝试了 npm run dev 并得到以下错误,同样的权限被拒绝时发生使用 yarn encore dev

我正在使用 debian 9

kamii@kamii-workstation:~$ node -v
v10.9.0
kamii@kamii-workstation:~$ npm -v
6.4.1
kamii@kamii-workstation:~$ yarn -v
1.9.4

通过 NPM:

kamii@kamii-workstation:/media/disks/Development/dev_lab_gen/exim_pos$ npm run dev

> @ dev /media/disks/Development/dev_lab_gen/exim_pos
> encore dev

sh: 1: encore: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! @ dev: `encore dev`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/kamii/.npm/_logs/2018-09-03T20_11_01_530Z-debug.log

通过纱线

kamii@kamii-workstation:/media/disks/Development/dev_lab_gen/exim_pos$ yarn encore dev
yarn run v1.9.4
$ /media/disks/Development/dev_lab_gen/exim_pos/node_modules/.bin/encore dev
/bin/sh: 1: /media/disks/Development/dev_lab_gen/exim_pos/node_modules/.bin/encore: Permission denied
error Command failed with exit code 126.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

这是 NPM 日志文件

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ]
2 info using npm@6.4.1
3 info using node@v10.9.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle @~predev: @
6 info lifecycle @~dev: @
7 verbose lifecycle @~dev: unsafe-perm in lifecycle true
8 verbose lifecycle @~dev: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/media/disks/Development/dev_lab_gen/exim_pos/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
9 verbose lifecycle @~dev: CWD: /media/disks/Development/dev_lab_gen/exim_pos
10 silly lifecycle @~dev: Args: [ '-c', 'encore dev' ]
11 silly lifecycle @~dev: Returned: code: 126  signal: null
12 info lifecycle @~dev: Failed to exec dev script
13 verbose stack Error: @ dev: `encore dev`
13 verbose stack Exit status 126
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:961:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
14 verbose pkgid @
15 verbose cwd /media/disks/Development/dev_lab_gen/exim_pos
16 verbose Linux 4.9.0-8-amd64
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
18 verbose node v10.9.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 126
22 error @ dev: `encore dev`
22 error Exit status 126
23 error Failed at the @ dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 126, true ]

我将参考@Jose 的评论并分享一些常见的陷阱:

在安装 encore 时,您是否放置了 -g(对于全局)标志?如果不是,那可能是原因。

另一个常见的事情是你的 encore 确实是全局安装的(可能是 /usr/local/bin)但是你 OS 没有看到它。这可能仅仅是因为 $PATH 不好。尝试 运行 source ~/.bash_profile 然后重试。如果您仍然无法 运行 它,则该路径可能未包含在您的 $PATH 中。

最后,几个月前我在全新安装 Centos 时遇到了这个问题,node 一直无法在全局安装任何东西。 Google 上的教程只会告诉您 chmod 777 您的 /usr/bin/usr/local/bin,这完全是个坏主意。相反,将您的 node 配置为其模块使用不同的目标路径。

希望对您有所帮助...

试试这个: ./node_modules/.bin/encore dev-server

如果是这样,您可能已经全局安装了 encore,因此当您 运行 它时,您没有在全局文件夹中执行它的权限。

echo $PATH看看安可有没有

我在默认情况下挂载了 noexec 标志的分区上。在 /etc/fstab 中显式添加 exec 标志解决了我的问题,甚至解决了 gulp.

的其他一些权限问题

User mounted partitions, e.g. when using the ‘user’ or ‘users’ mount options in the /etc/fstab file, are done with the ‘noexec’ mount option by default for security reasons. This means that memory mapping (mmap) files for execution will be denied. Another reason can be the lack of kernel support for shared writable mmap which was added to Linux kernel 2.6.26.

Solution: Add the ‘exec’ mount option to the end of the mount options. It’s important that the option to be the last one, otherwise other mount option can over judge its effect. However please also note that Wine was not designed to run arbitrary applications directly from a Windows partition. To do so, one must install the Windows application via Wine onto the Windows partition first.

就我而言,删除 node_modules 文件夹和 运行 yarn install 有帮助。我的目录权限发生了变化,它影响了本地安装的 encore。