Open gianfa opened 6 days ago
@gianfa unfortunately you are hit by a package hard to package with webpack.
We try to hide webpack configuration to the developer to ease its life. But in your specific case, you gonna need to provide a customization of the configuration. This is explained in the documentation.
That said, I think you should reconsider using winston. There are mainly two execution environments for JavaScript: web browsers (like JupyterLab extension) and Node.JS servers. From a quick internet search, winston does not seem to be well suited for frontend.
Description
Hi, using winston I run into an error related to webpack v>=5, as you can see below.
I tried implementing several strategies found online, including setting a polyfill from webpack.config.js, but to no avail.
Please let me know if I am doing something wrong or possibly how to fix it. Winston is very convenient for logging.
Partial Error Output
Open for the Full Error Output
```shell (testenv) hatch run jlpm run build Building extension in . Compilation starting… ModuleNotFoundError: Module not found: Error: Can't resolve 'util' in '/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/winston' 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: { "util": require.resolve("util/") }' - install 'util' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "util": false } at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/Compilation.js:2123:28](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/Compilation.js:2123:28) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:923:13](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:923:13) at eval (eval at create (/myuser/Desktop/test-winston-hidden/extension/node_modules/tapable/lib/HookCodeFactory.js:33:10),Reproduce
To reproduce it, just install winston and invoke it.
Example
From the extension directory
Use the following as your src/index.js file
// ------- offending code ------- import * as winston from 'winston'; const logger = winston.createLogger({ level: 'info', transports: [ new winston.transports.Console() ] }); logger.info("Test") // ------- /offending code -------
/**
Initialization data for the myext extension. */ const plugin: JupyterFrontEndPlugin = {
id: 'myext:plugin',
description: 'A JupyterLab extension to test winston',
autoStart: true,
activate: (app: JupyterFrontEnd) => {
console.log('JupyterLab extension myext is activated!');
}
};
export default plugin;
A .zip file is provided in order to fully reproduce the behaviour, see below.
Expected behavior
The build finish succesfully
E.g.
Context
"@jupyterlab/application": "^4.0.0"
Package to fully reproduce the error
Below I attach a zip file to reproduce the case. It has a “reproduce.sh” script, by running which the mock extension is reproduced, so that if something is wrong in the installation it is clearly visible.
test-winston.zip