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

move const def under main condition - do not init until needed #1155

Closed
wants to merge 1 commit into from

Conversation

wesoledi
Copy link
Contributor

@wesoledi wesoledi commented Oct 9, 2022

@wesoledi
Copy link
Contributor Author

wesoledi commented Oct 9, 2022

Fix for error, while running 'npm run build' on some enviroments (with restriction on available ports).

The error was:

[webpack-cli] Failed to load '<path>/webpack.config.js' config
[webpack-cli] Error: Timed out waiting for sync-rpc server to start (it should respond with "pong" when sent "ping"):

More here: #1154

@wesoledi wesoledi changed the title 2022-08-15 - move const def under main condition - do not init until needed move const def under main condition - do not init until needed Oct 9, 2022
@@ -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'));
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

@wesoledi wesoledi Oct 10, 2022

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

@michalhorak
Copy link

Please allow me to ask you to reconsider the initial request.
I just had some disturbing moments looking for a solution in all wrong places at first.
2022-12-19 21_15_24-sync-rpc-out
The problem appeared irregularly. When it started to appear, it was always just the first run (bearable). Recently it became much more frequent. As I am sort of learning to use your wonderful software, I first attempted to exclude all possible misconfigurations on my side, removed node_modules, antivirus ... I did not at all know there is any use of eslint (which I do not use with encore) during packing.

After finally reading this thread I manually performed the request in local 'node_modules' and all is well.

IMHO:
Importing files which are not at all used seems as unnecessary delay to me. I was moreover at first confused and thought I have some misconfiguration in .eslintrc.json (which I use only with IDE), and that is somehow parsed by Encore and disturbes it. By various experiments I discovered it is not the case.

In case of transition to ES6 modules you can use import() for the same purpose.
Thank you.

@weaverryan
Copy link
Member

Please allow me to ask you to reconsider the initial request.

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!

@weaverryan weaverryan closed this Dec 20, 2022
weaverryan added a commit that referenced this pull request Apr 19, 2023
This PR was merged into the main branch.

Discussion
----------

Delay force sync until needed

Hi!

This finishes #1155.

Cheers!

Commits
-------

ca95954 moving most require back to the top
530eed5 2022-08-15 - move const def under main condition - do not init if not nessesary
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

Successfully merging this pull request may close these issues.

5 participants