webpack: Cannot read property 'match' of undefined

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

I have installed webpack (Symfony encore) using npm as follows:

sudo npm install -g @symfony/webpack-encore --save-dev

I ran this from /var/www/project

I was required to install globally due to issues with package managers and shared folders when dealing with Windows host / Linux guest.

I cannot install webpack (node_modules) in the same directory (or under it) as the /var/www/project

So my package.json file looks like this:

{   "name": "test",     "version": "1.0.0",   "description": "This is a test",   "main": "index.js",   "dependencies": {},   "devDependencies": {     "@symfony/webpack-encore": "^0.15.0"   },   "scripts": {     "test": "echo \"Error: no test specified\" && exit 1"   },   "author": "Alex",     "license": "MIT" } 

I run encore from /var/www/project using this

/usr/local/bin/encore dev

I get this lovely output in return:

Running webpack ...    TypeError: Cannot read property 'match' of undefined    - index.js:125 parse     [lib]/[webpack-encore]/[yargs-parser]/index.js:125:12    - index.js:761 Function.Parser.detailed     [lib]/[webpack-encore]/[yargs-parser]/index.js:761:10    - yargs.js:938 Object.Yargs.self._parseArgs     [lib]/[webpack-encore]/[yargs]/yargs.js:938:27    - yargs.js:927 Object.get [as argv]     [lib]/[webpack-encore]/[yargs]/yargs.js:927:19    - index.js:725 Object.configureRuntimeEnvironment     [lib]/[@symfony]/webpack-encore/index.js:725:54    - index.js:770 Proxy.parameters     [lib]/[@symfony]/webpack-encore/index.js:770:45    - webpack.config.js:3 Object.<anonymous>     /var/www/project/webpack.config.js:3:8    - module.js:573 Module._compile     module.js:573:30    - module.js:584 Object.Module._extensions..js     module.js:584:10    - module.js:507 Module.load     module.js:507:32 

What am I missing?

回答1:

simple answer just run rm -rf package-lock.json



回答2:

Try to remove package-lock.json and after that run npm install



回答3:

An additional reason for this message can be a mismatch between the npm major version that the package-lock.json was generated with and the version the npm install is run on.

If for example the lockfile was generated using npm@5 and later you try to npm install on npm@6 because of lets say a minor node@8 update you will see this error.

The solution here is like mentioned in the other answers to remove node_modules and package-lock.json and npm install on npm@6 again. Or stay on npm@5 for lockfile and later install.



回答4:

Installing webpack-encore globally is currently not supported. The error message however is not really explanatory.

There is an issue open to improve this error message: https://github.com/symfony/webpack-encore/issues/36

You should try to install webpack-encore locally, this is the real issue here.



回答5:

After adding an argument to the configureRuntimeEnvironment method it started working for me:

Encore.configureRuntimeEnvironment('dev'); 

Somehow if you omit the argument(s) the error keeps showing up.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!