Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getWebpackVersion does not work properly #309

Closed
0pt1m1z3r opened this issue Sep 21, 2018 · 14 comments
Closed

getWebpackVersion does not work properly #309

0pt1m1z3r opened this issue Sep 21, 2018 · 14 comments

Comments

@0pt1m1z3r
Copy link

0pt1m1z3r commented Sep 21, 2018

Do you want to request a feature, report a bug or ask a question?
Bug

What is the current behavior?
svg-sprite-loader have webpack 4 in dependencies.
getWebpackVersion return version for webpack in {project}/node_modules/svg-sprite-loader/node_modules/webpack/package.json

What is the expected behavior?
getWebpackVersion should return version for webpack in {project}/node_modules/webpack/package.json

If the current behavior is a bug, please provide the steps to reproduce, at least part of webpack config with loader configuration and piece of your code.
I just run my nuxt.js project and get this error:

basic chunk optimization/{project}/node_modules/svg-sprite-loader/lib/utils/get-module-chunk.js:14
    chunks = Array.from(module.chunksIterable);
                   ^

TypeError: Cannot convert undefined or null to object`

Please tell us about your environment:

  • Node.js version: 8
  • webpack version: 3
  • svg-sprite-loader version: last
  • OS type & version: macOs
@0pt1m1z3r
Copy link
Author

Проще по русски написать :)
Ошибка возникает в get-module-chunk.js, условие webpackVersion.IS_4 верно, хотя у меня стоит 3 вебпак.

@kisenka
Copy link
Contributor

kisenka commented Sep 27, 2018

Could you please create repo with minimal setup to demonstrate a problem (package.json, webpack config, SVG image and piece of your code). If you don't want to create a repository - you can create a gist with multiple files.

@Gagydzer
Copy link
Contributor

fixed..

@kisenka
Copy link
Contributor

kisenka commented Apr 27, 2019

Fixed in svg-sprite-loader@4.1.4, please update

@kisenka kisenka closed this as completed Apr 27, 2019
@williansabiao
Copy link

@kisenka I had to go back to the version svg-sprite-loader@4.1.3 because my Cypress was breaking after 4.1.3.
It couldn't find the require.main.require('webpack...').

Although, the last version worked well with my App and storybook.

@kisenka
Copy link
Contributor

kisenka commented Apr 30, 2019

@williansabiao which NodeJS version is used?

@williansabiao
Copy link

The Cypress uses his own Node build. It's v8.2.1 😞 .

I just saw they are working on to update it. So, probably it is the reason I'm getting the error in the new versions of svg-sprite-loader, right?

I guess I can update to a newer version when Cypress update as well. That's ok. Thanks.

@linqcan
Copy link

linqcan commented May 29, 2019

Just wanted to highlight that this change (PR #314 ) breaks builds where webpack is started from a global Node.js application such as a global Gulp installation.

In that case the main entry point for Node.js will be the global Gulp and its paths (global paths) will be present in require.main.paths. If you don't happen to have webpack globally installed the webpack lookup will fail.

I have found the following workarounds:

  • Use local Gulp through npx or similar
  • Patch require.main.paths with the local "node_modules" folder in my gulpfile.js so that the webpack lookup works (however this makes "global" "local", your milage may vary). This is the solution I have chosen since I need to run global Gulp (using the Task Runner in Visual Studio)

Not sure if this is a problem that this of concern for this module, but since others might encounter the same issue I post my findings here.

@Nettsentrisk
Copy link

I'm also running into this problem when running ESLint (with eslint-import-resolver-webpack).

This line:
const webpackVersion = require.main.require('webpack/package.json').version;

Causes this error:

Error: Cannot find module 'webpack/package.json'

@ivan-podgornov
Copy link

ivan-podgornov commented Aug 29, 2019

I use lerna and there is two directories: with builder and with sites. When I bootstrap builder to each site, this error is causing:

Error: Cannot find module 'webpack/package.json'

@ViieeS
Copy link

ViieeS commented Apr 8, 2020

Is there any way to make it work with eslint-import-resolver-webpack?

@kisenka
Copy link
Contributor

kisenka commented Apr 12, 2020

@williansabiao @linqcan @Nettsentrisk @ivan-podgornov @ViieeS

Using autodetecting webpack version was very bad idea. I've published alpha version without detecting webpack version, could some of you guys help me with trying it out?

npm install svg-sprite-loader@drop-webpack-version-detector

@ViieeS
Copy link

ViieeS commented Apr 17, 2020

@kisenka works fine! Thank you!

Make PR, please.

@kisenka
Copy link
Contributor

kisenka commented Apr 26, 2020

Published in svg-sprite-loader@4.2.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants