JetBrains / svg-sprite-loader

Webpack loader for creating SVG sprites.
MIT License
2.02k stars 273 forks source link

getWebpackVersion does not work properly #309

Closed 0pt1m1z3r closed 5 years ago

0pt1m1z3r commented 6 years ago

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:

0pt1m1z3r commented 6 years ago

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

kisenka commented 6 years ago

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 commented 6 years ago

fixed..

kisenka commented 5 years ago

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

williansabiao commented 5 years ago

@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 commented 5 years ago

@williansabiao which NodeJS version is used?

williansabiao commented 5 years ago

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 commented 5 years ago

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:

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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

kisenka commented 4 years ago

@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 commented 4 years ago

@kisenka works fine! Thank you!

Make PR, please.

kisenka commented 4 years ago

Published in svg-sprite-loader@4.2.6