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

Possible dependency conflict with Ktor #565

Open
JoonasC opened this issue Feb 28, 2025 · 4 comments
Open

Possible dependency conflict with Ktor #565

JoonasC opened this issue Feb 28, 2025 · 4 comments

Comments

@JoonasC
Copy link

JoonasC commented Feb 28, 2025

Ktor recently had an issue where webpack would fail to bundle due to an outdated dependency version: https://youtrack.jetbrains.com/issue/KTOR-7912/Module-not-found-errors-when-executing-browserProductionWebpack-task-since-3.0.2.

This issue should have been fixed with the release of Ktor 3.0.3, however I am still getting the same issue:

Module not found: Error: Can't resolve 'zlib' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "zlib": require.resolve("browserify-zlib") }'
        - install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "zlib": false }

Module not found: Error: Can't resolve 'stream' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'
Did you mean './stream'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, ../../processedResources/js/main).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

Module not found: Error: Can't resolve 'stream' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'
Did you mean './stream'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, ../../processedResources/js/main).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

Module not found: Error: Can't resolve 'crypto' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }

Module not found: Error: Can't resolve 'stream' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'
Did you mean './stream'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, ../../processedResources/js/main).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

Module not found: Error: Can't resolve 'buffer' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
        - install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "buffer": false }

Module not found: Error: Can't resolve 'http' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }

Module not found: Error: Can't resolve 'stream' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'
Did you mean './stream'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, ../../processedResources/js/main).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

Module not found: Error: Can't resolve 'crypto' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }

Module not found: Error: Can't resolve 'https' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
        - install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "https": false }

Module not found: Error: Can't resolve 'http' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }

Module not found: Error: Can't resolve 'net' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

Module not found: Error: Can't resolve 'tls' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

Module not found: Error: Can't resolve 'crypto' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }

Module not found: Error: Can't resolve 'stream' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'
Did you mean './stream'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, ../../processedResources/js/main).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

Module not found: Error: Can't resolve 'url' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
        - install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "url": false }

Module not found: Error: Can't resolve 'bufferutil' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

Module not found: Error: Can't resolve 'utf-8-validate' in '/home/joonas/Documents/Projects/Dynavio/DACM/frontend/build/js/node_modules/ws/lib'

webpack 5.94.0 compiled with 16 errors and 2 warnings in 2660 ms

Could there be a conflict between the dependencies of Kvision and Ktor?

I am using the latest version of Kvision (8.2.0).

@JoonasC
Copy link
Author

JoonasC commented Feb 28, 2025

Another possible cause could be that the webpack config files that come with Kvision by default are somehow causing this issue.

Here is my webpack.js config file:

config.resolve.modules.push("../../processedResources/js/main");
config.resolve.conditionNames = ['import', 'require', 'default'];

if (config.devServer) {
    config.devServer.hot = true;
    config.devServer.open = false;
    config.devServer.port = 3000;
    config.devServer.historyApiFallback = true;
} else {
    config.devtool = undefined;
}

// disable bundle size warning
config.performance = {
    assetFilter: function (assetFilename) {
      return !assetFilename.endsWith('.js');
    },
};

@rjaros
Copy link
Owner

rjaros commented Feb 28, 2025

Yes, you are right. Default KVision webpack configuration makes problems with dependency resolution in the ws package. Change the second line of your webpack.js to this:

config.resolve.conditionNames = ['import', 'require', 'default', 'browser'];

It fixed the issue in my test app.

@JoonasC
Copy link
Author

JoonasC commented Feb 28, 2025

Thanks, might be a good idea to update the default webpack config if it doesn't break anything. You can close this now if you want.

@rjaros
Copy link
Owner

rjaros commented Feb 28, 2025

First I need to check, if this custom configuration is still needed. It was necessary some time ago for Chart.js module. I'll leave this issue open.

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

2 participants