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

require.main.require overwriting causes problems with vscode #381

Closed
719media opened this issue Mar 3, 2020 · 8 comments
Closed

require.main.require overwriting causes problems with vscode #381

719media opened this issue Mar 3, 2020 · 8 comments

Comments

@719media
Copy link
Contributor

719media commented Mar 3, 2020

Hello,
I am having a problem where vscode eslint is "crapping out" after including this library.
I get that this is probably a problem with vscode, and not with svg-sprite-loader.

The problem is specifically this line here:
https://github.com/JetBrains/svg-sprite-loader/blob/master/lib/utils/get-webpack-version.js#L6

Which results in the vscode error Cannot find module webpack/package.json

Because of this error, eslint effectively "breaks" inside of vscode. If I hardcode const webpackVersion = 4, everything works great.

I'm not exactly sure why eslint inside of vscode can't "resolve" this path on installation, but this is my finding so far.

I see that webpack has a version property, but it appears this property was only added since webpack 4, and apparently you support webpack 2-4, so I understand that it is not a solution.

@xidb
Copy link

xidb commented Mar 3, 2020

Made a PR for that here #382

@719media
Copy link
Contributor Author

719media commented Mar 3, 2020

For what it's worth, I still get the error with this PR. May be related to microsoft/TypeScript#19117

If I use just straight up require, or change the conditional to be if (!require.main || !require.main.require || true) {, then vscode + eslint works just fine. I'm guessing that require.main within vscode + eslint points to the node used internally, which doesn't have webpack, which is why this jacks everything up.

@719media 719media changed the title Hard to define error with package.json version and vscode require.main.require overwriting causes problems with vscode Mar 3, 2020
@719media
Copy link
Contributor Author

719media commented Mar 3, 2020

PR #383 addresses my problems. I have included the PR #382 into #383. There may be another way to address this problem, but this is what I went with.

@xidb
Copy link

xidb commented Mar 3, 2020

For what it's worth, I still get the error with this PR.

That's right, i updated my PR.

@719media
Copy link
Contributor Author

719media commented Mar 3, 2020

OK Cool. To hopefully expedite this, I've closed #383 since it is now a duplicate of #382

@719media
Copy link
Contributor Author

719media commented Apr 2, 2020

@kisenka Please consider this issue. There is a PR to fix it. Happy to change it in any way. I'm not sure that the supplied PR #382 fixes it in my preferred way (the PR treats the "default" webpack version as 4, instead of null or empty string), but it would be awesome to get something in there so that vscode users using linting get back on latest branch.
My preferred way is #383 (very simple PR), but please provide feedback one way or another.
Thank you.

@kisenka
Copy link
Contributor

kisenka commented Apr 12, 2020

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

@kisenka
Copy link
Contributor

kisenka commented May 10, 2020

Detecting webpack version has been dropped 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

3 participants