-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
Issue with no-unpublished-require
and devDependencies
modules
#47
Comments
Thank you for this issue.
That rule disallows imports of unpublished files/modules from published files. (Because such imports may cause severe problems after If you don't have both "files" field of package.json and .npmignore, your all files would be published. |
https://github.com/mysticatea/eslint-plugin-node/blob/master/package.json#L5 Like this, I'd like to recommend to use "files" field of package.json. |
This tripped me up as well. After reading this issue I understand why, but I feel like the docs for this rule could be more clear in stating that the rule will fail if you try to load devDependencies. I surely can't be the only person using this rule in an application (as opposed to a package) that will never be published to npm. |
+1 here, supertest and knex-cleaner package are causing that problem in my new API too. :/ |
I would definitely not want to publish code that has That said, I do think we need a way to change the way this rule works for development files (e.g. tests). It's absolutely okay for a test to For now, I'm just going to disable this rule for my test directories. But it would be nice to have a way to protect them from mistakes, too. |
A few day ago, I updated the document about this. |
This issue happens to me very often, can we get other error message if dependency is present in |
This issue comes up when you have development scripts. For example, I have a script that requires It's a very confusingly named lint error, because |
If it helps someone, just fixed this adding another
|
And for other like me who keep their tests next to their components rather than in one top level folder, you can add an override to your top {
"overrides": [{
"files": "**/*.test.js",
"rules": {
"node/no-unpublished-require": 0,
"node/no-missing-require": 0
}
}]
} |
Another optional workaround is to include the devependancy in |
@ntwb Just to fullfill eslint-node-plugin needs I would never move my project dependencies to peer that can produce other effects. After reading the issue the solution should be clear: Either you
@mysticatea What's left here is the situation that this rule shouldn't be applied on private packages because they can't be published. In my case I get errors for private packages. |
I also encountered this problem with a private unpublished project. The way to fix this was to add Depends on how you look at it this might be either a proper solution or an ugly workaround, I'm not sure myself. |
Old issue, but devDependencies can be easily allowed in some files with something like this: const packageJson = require('./package.json')
const devDependencies = Object.keys(packageJson.devDependencies || {})
module.exports = {
// your eslint config...
rules: {
'node/no-unpublished-require': ['error', {
'allowModules': devDependencies
}]
}
} |
Just to have it mentioned for others as I had a bit of trouble understanding the issue related to devDependencies ad-hoc, but figured it out. Great to see this checked btw. Thanks again for getting this checked - leading to very clean published packages! GJ 🦸 |
What was done and why: - After the `stream` module, the modules `util` and `process` had to be added to the dependencies as well in order to satisfy Webpack v5 which does not include polyfills anymore, otherwise tests were failing. - https://webpack.js.org/migrate/5/ - https://webpack.js.org/configuration/resolve/#resolvefallback - https://github.com/ef4/ember-auto-import/blob/v2.6.0/docs/upgrade-guide-2.0.md - https://gist.github.com/ef4/d2cf5672a93cf241fd47c020b9b3066a For the `process` module, adding it to the `fallback` key was not working, it had to be included in the `plugins` key: - https://stackoverflow.com/questions/65018431/webpack-5-uncaught-referenceerror-process-is-not-defined/65018686#65018686 - https://discord.com/channels/480462759797063690/898671957007011841/898682272847384596 Overall, these messages on Discord give the entire final solution in this commit. - `wepack` moved to the dependencies because otherwise `eslint-plugin-n` was returning the error: ``` "webpack" is not published.eslintn/no-unpublished-require ``` See: - https://github.com/eslint-community/eslint-plugin-n/blob/15.6.1/docs/rules/no-unpublished-require.md - mysticatea/eslint-plugin-node#47
What was done and why: - After the `stream` module, the modules `util` and `process` had to be added to the dependencies as well in order to satisfy Webpack v5 which does not include polyfills anymore, otherwise tests were failing. - https://webpack.js.org/migrate/5/ - https://webpack.js.org/configuration/resolve/#resolvefallback - https://github.com/ef4/ember-auto-import/blob/v2.6.0/docs/upgrade-guide-2.0.md - https://gist.github.com/ef4/d2cf5672a93cf241fd47c020b9b3066a For the `process` module, adding it to the `fallback` key was not working, it had to be included in the `plugins` key: - https://stackoverflow.com/questions/65018431/webpack-5-uncaught-referenceerror-process-is-not-defined/65018686#65018686 - https://discord.com/channels/480462759797063690/898671957007011841/898682272847384596 Overall, these messages on Discord give the entire final solution in this commit. - `wepack` moved to the dependencies because otherwise `eslint-plugin-n` was returning the error: ``` "webpack" is not published.eslintn/no-unpublished-require ``` See: - https://github.com/eslint-community/eslint-plugin-n/blob/15.6.1/docs/rules/no-unpublished-require.md - mysticatea/eslint-plugin-node#47
What was done and why: - After the `stream` module, the modules `util` and `process` had to be added to the dependencies as well in order to satisfy Webpack v5 which does not include polyfills anymore, otherwise tests were failing. - https://webpack.js.org/migrate/5/ - https://webpack.js.org/configuration/resolve/#resolvefallback - https://github.com/ef4/ember-auto-import/blob/v2.6.0/docs/upgrade-guide-2.0.md - https://gist.github.com/ef4/d2cf5672a93cf241fd47c020b9b3066a For the `process` module, adding it to the `fallback` key was not working, it had to be included in the `plugins` key: - https://stackoverflow.com/questions/65018431/webpack-5-uncaught-referenceerror-process-is-not-defined/65018686#65018686 - https://discord.com/channels/480462759797063690/898671957007011841/898682272847384596 Overall, these messages on Discord give the entire final solution in this commit. - `wepack` moved to the dependencies because otherwise `eslint-plugin-n` was returning the error: ``` "webpack" is not published.eslintn/no-unpublished-require ``` See: - https://github.com/eslint-community/eslint-plugin-n/blob/15.6.1/docs/rules/no-unpublished-require.md - mysticatea/eslint-plugin-node#47
* build: upgrade Ember.js from v3.28.3 to v4.10.0 * refactor: use buil-in tests setup wrappers * refactor: standardise helper & fix types checks - Standardise helper's function signature and body To match what is generated by default when creating a new helper. - Fix types errors provided by implicit TypeScript checks This will help whenever the project is migrated to TS * test: fix test, add required Webpack polyfills What was done and why: - After the `stream` module, the modules `util` and `process` had to be added to the dependencies as well in order to satisfy Webpack v5 which does not include polyfills anymore, otherwise tests were failing. - https://webpack.js.org/migrate/5/ - https://webpack.js.org/configuration/resolve/#resolvefallback - https://github.com/ef4/ember-auto-import/blob/v2.6.0/docs/upgrade-guide-2.0.md - https://gist.github.com/ef4/d2cf5672a93cf241fd47c020b9b3066a For the `process` module, adding it to the `fallback` key was not working, it had to be included in the `plugins` key: - https://stackoverflow.com/questions/65018431/webpack-5-uncaught-referenceerror-process-is-not-defined/65018686#65018686 - https://discord.com/channels/480462759797063690/898671957007011841/898682272847384596 Overall, these messages on Discord give the entire final solution in this commit. - `wepack` moved to the dependencies because otherwise `eslint-plugin-n` was returning the error: ``` "webpack" is not published.eslintn/no-unpublished-require ``` See: - https://github.com/eslint-community/eslint-plugin-n/blob/15.6.1/docs/rules/no-unpublished-require.md - mysticatea/eslint-plugin-node#47
If I use this code:
With the rule:
And AVA is in my
package.json
:I get the warning:
1:22 error "ava" is not published node/no-unpublished-require
The rule readme says:
Am I correct in reading that this should not error if the module is in
devDependencies
?The text was updated successfully, but these errors were encountered: