We are using eslint with the eslint-import-resolver-webpack package, and everything was working great until we upgraded webpacker. After running webpacker:install to update the config files, we started getting lots of strange eslint warnings like this:
1:1 error Resolve error: Cannot read property 'host' of undefined import/no-unresolved
1:1 error Resolve error: Cannot read property 'host' of undefined import/no-extraneous-dependencies
1:1 error Resolve error: Cannot read property 'host' of undefined import/no-duplicates
1:1 error Resolve error: Cannot read property 'host' of undefined import/extensions
1:1 error Resolve error: Cannot read property 'host' of undefined import/no-absolute-path
1:1 error Resolve error: Cannot read property 'host' of undefined import/no-named-as-default
1:1 error Resolve error: Cannot read property 'host' of undefined import/no-named-as-default-member
2:1 error 'components' should be listed in the project's dependencies. Run 'npm i -S components' to add it import/no-extraneous-dependencies
We eventually figured out that all these errors were caused by using absolute imports for files in our projects (e.g. import foo from 'components/foo'). My hunch is that this is related to the way the webpack config loads yaml files, but I'm not sure how to fix it.
@RobinClowers Seems like a configuration problem with eslint and not particularly related to Webpacker. You can ignore webpack folder in eslint config.
@gauravtiwari you're right, it is an eslint configuration issue. I was able the work around this by not using absolute imports, but that was working fine before I upgraded webpacker. :man_shrugging:
Also, ignoring the webpack config would not work, these errors were coming from code in app/javascript.
Cool, thanks for sharing 馃憤 Perhaps one of the dependencies got bumped up when you did upgrade earlier from 1.1 to 1.2.
@gauravtiwari I had another chance to look at this, and it turns out the problem is that the generated webpack/configration.js assumes NODE_ENV is set, which isn't always the case. Would you accept a PR that defaults it to development?
@RobinClowers Are you running the server/compiler scripts through yarn instead of binstubs provided?
Right, I'm running eslint through yarn, which seems like a pretty normal thing. eslint-import-resolver-webpack automatically invokes webpack, I don't know that I have control over how it does that.
@RobinClowers Could you try this please NODE_ENV=development yarn lint since this is special case?
Indeed, that does fix my issue. Still, it doesn't seem like I should have to specify the env every time?
May be something like this would save some typing ;)
"scripts": {
"lint": "NODE_ENV=development eslint app/javascript/packs"
}
Actually, I made this change in another PR, but that's still in review so lets keep it as is for now.
You made the change to default the env? I just want to help other people avoid this sharp edge. Also, thanks for being so responsive on this issue. 鉂わ笍
Yepp, but that PR is a big change so, would probably take some time - https://github.com/rails/webpacker/pull/264/files#diff-9f42d25c3b13e34aaf7b3d5837bd3d39R4 馃憤 No worries 鉂わ笍