-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
move const def under main condition - do not init until needed #1155
Conversation
Fix for error, while running 'npm run build' on some enviroments (with restriction on available ports). The error was:
More here: #1154 |
@@ -25,6 +18,13 @@ const babelLoaderUtil = require('../loaders/babel'); | |||
*/ | |||
module.exports = function(plugins, webpackConfig) { | |||
if (webpackConfig.useEslintPlugin) { | |||
const forceSync = require('sync-rpc'); | |||
const hasEslintConfiguration = forceSync(require.resolve('../utils/has-eslint-configuration')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move ONLY these 2 lines and put the below 4 back on top? For clarity, I'd like to only move the items that are actually creating the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even the import of sync-rpc
might not be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point - it is likely just the hasEslintConfiguration
that is the problem since it is USING sync-rpc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sync-rpc it is the main problem for this error. It tried to connect on initialization on import so it is mandatory, to fix this issue.
Can we only move this one? Maybe, I didnt tried. Maybe you are right, sync-rpc can stay, but I moved all, because I believe, there is no point to init or import all of this things if we would not use it at all, because of the if condition. Waste of resources in my opinion. Import and use it only when we need to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waste of resources in my opinion. Import and use it only when we need to.
It is a matter of code clarity. We normally expect require
statements to be at the top of the file. If we start requiring them inline, it'll make the code harder to follow. That's a waste of human resources :). That's why we want to move only the one line needed. That one line actually should have always been moved down here because we are USING a library, not just doing a simple require
. But the other require
are standard and should be at the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wesoledi the error in the reported issue has a stack trace pointing to line 13, which means the line calling forceSync()
, not the line importing it. So require('sync-rpc')
is not the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thus, if we migrate to ESM imports in the future (not planned yet, but it might happen at some point as that's the future of the ecosystem), imports are required to be at the top-level. So our existing convention of requiring deps at the top-level will make that migration easier.
Please allow me to ask you to reconsider the initial request. After finally reading this thread I manually performed the request in local 'node_modules' and all is well. IMHO: In case of transition to ES6 modules you can use import() for the same purpose. |
Oh, I definitely support this PR :). We just got tangled in some final details. I've finished it over in #1175. I'd love if you could confirm that this small change fixes your issue. Closing this PR - as the original work + new tweaks is over on #1175. Cheers! |
#1154