jupyterlab / extension-template

A `copier` template for JupyterLab extensions
Creative Commons Zero v1.0 Universal
54 stars 18 forks source link

Build fails with winston: `BREAKING CHANGE: webpack < 5` #90

Open gianfa opened 6 days ago

gianfa commented 6 days ago

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

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 }
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), :10:1) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:339:22](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:339:22) at eval (eval at create (/myuser/Desktop/test-winston-hidden/extension/node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:520:22](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:520:22) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:151:10](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:151:10) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:783:25](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:783:25) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:1008:8](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:1008:8) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:1137:5](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/NormalModuleFactory.js:1137:5) resolve 'util' in '/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/winston' Parsed request is a module using description file: [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/package.json](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/package.json) (relative path: [./dist/winston](https://file+.vscode-resource.vscode-cdn.net/Users/giana/Desktop/Github/PrometeiaWork/PromWork/libs-devops/mp_jh_ui-new-template/dist/winston)) Field 'browser' doesn't contain a valid alias configuration resolve as module [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/winston/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/winston/node_modules) doesn't exist or is not a directory [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/node_modules) doesn't exist or is not a directory [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/node_modules) doesn't exist or is not a directory [/myuser/Desktop/test-winston-hidden/extension/node_modules/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/node_modules) doesn't exist or is not a directory looking for modules in [/myuser/Desktop/test-winston-hidden/extension/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules) single file module using description file: [/myuser/Desktop/test-winston-hidden/extension/package.json](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/package.json) (relative path: [./node_modules/util](https://file+.vscode-resource.vscode-cdn.net/Users/giana/Desktop/Github/PrometeiaWork/PromWork/libs-devops/mp_jh_ui-new-template/node_modules/util)) no extension Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util) doesn't exist .js Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util.js](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util.js) doesn't exist .json Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util.json](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util.json) doesn't exist .wasm Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util.wasm](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util.wasm) doesn't exist [/myuser/Desktop/test-winston-hidden/extension/node_modules/util](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util) doesn't exist [/myuser/Desktop/test-winston-hidden/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/node_modules) doesn't exist or is not a directory [/myuser/Desktop/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/node_modules) doesn't exist or is not a directory [/myuser/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/node_modules) doesn't exist or is not a directory [/Users/node_modules](https://file+.vscode-resource.vscode-cdn.net/Users/node_modules) doesn't exist or is not a directory [/node_modules](https://file+.vscode-resource.vscode-cdn.net/node_modules) doesn't exist or is not a directory [/myuser/Desktop/test-winston-hidden/extension/node_modules/](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/)@jupyterlab/builder/lib/build-labextension.js:104 throw new Error(err.details); ^ Error: resolve 'util' in '/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/winston' Parsed request is a module using description file: [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/package.json](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/package.json) (relative path: [./dist/winston](https://file+.vscode-resource.vscode-cdn.net/Users/giana/Desktop/Github/PrometeiaWork/PromWork/libs-devops/mp_jh_ui-new-template/dist/winston)) Field 'browser' doesn't contain a valid alias configuration resolve as module [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/winston/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/winston/node_modules) doesn't exist or is not a directory [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/dist/node_modules) doesn't exist or is not a directory [/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/winston/node_modules) doesn't exist or is not a directory [/myuser/Desktop/test-winston-hidden/extension/node_modules/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/node_modules) doesn't exist or is not a directory looking for modules in [/myuser/Desktop/test-winston-hidden/extension/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules) single file module using description file: [/myuser/Desktop/test-winston-hidden/extension/package.json](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/package.json) (relative path: [./node_modules/util](https://file+.vscode-resource.vscode-cdn.net/Users/giana/Desktop/Github/PrometeiaWork/PromWork/libs-devops/mp_jh_ui-new-template/node_modules/util)) no extension Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util) doesn't exist .js Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util.js](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util.js) doesn't exist .json Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util.json](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util.json) doesn't exist .wasm Field 'browser' doesn't contain a valid alias configuration [/myuser/Desktop/test-winston-hidden/extension/node_modules/util.wasm](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util.wasm) doesn't exist [/myuser/Desktop/test-winston-hidden/extension/node_modules/util](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/util) doesn't exist [/myuser/Desktop/test-winston-hidden/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/node_modules) doesn't exist or is not a directory [/myuser/Desktop/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/node_modules) doesn't exist or is not a directory [/myuser/node_modules](https://file+.vscode-resource.vscode-cdn.net/myuser/node_modules) doesn't exist or is not a directory [/Users/node_modules](https://file+.vscode-resource.vscode-cdn.net/Users/node_modules) doesn't exist or is not a directory [/node_modules](https://file+.vscode-resource.vscode-cdn.net/node_modules) doesn't exist or is not a directory at compilerCallback (/myuser/Desktop/test-winston-hidden/extension/node_modules/@jupyterlab/builder/lib/build-labextension.js:104:19) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/)@jupyterlab/builder/lib/build-labextension.js:146:21 at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/MultiCompiler.js:655:5](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/MultiCompiler.js:655:5) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/neo-async/async.js:2830:7](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/neo-async/async.js:2830:7) at done (/myuser/Desktop/test-winston-hidden/extension/node_modules/neo-async/async.js:2865:11) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/neo-async/async.js:2818:7](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/neo-async/async.js:2818:7) at [/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/HookWebpackError.js:67:2](https://file+.vscode-resource.vscode-cdn.net/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/HookWebpackError.js:67:2) at Hook.eval [as callAsync] (eval at create (/myuser/Desktop/test-winston-hidden/extension/node_modules/tapable/lib/HookCodeFactory.js:33:10), :15:1) at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/myuser/Desktop/test-winston-hidden/extension/node_modules/tapable/lib/Hook.js:18:14) at Cache.shutdown (/myuser/Desktop/test-winston-hidden/extension/node_modules/webpack/lib/Cache.js:154:23) Node.js v18.7.0 [/myuser/Library/Application](https://file+.vscode-resource.vscode-cdn.net/myuser/Library/Application) Support/hatch/env/virtual/myext/QH3Z3Wb8/myext/lib/python3.10/site-packages/jupyterlab/debuglog.py:54: UserWarning: An error occurred. warnings.warn("An error occurred.") [/myuser/Library/Application](https://file+.vscode-resource.vscode-cdn.net/myuser/Library/Application) Support/hatch/env/virtual/myext/QH3Z3Wb8/myext/lib/python3.10/site-packages/jupyterlab/debuglog.py:55: UserWarning: subprocess.CalledProcessError: Command '['node', '/myuser/Desktop/test-winston-hidden/extension/node_modules/@jupyterlab/builder/lib/build-labextension.js', '--core-path', '/myuser/Library/Application Support/hatch/env/virtual/myext/QH3Z3Wb8/myext/lib/python3.10/site-packages/jupyterlab/staging', '/myuser/Desktop/test-winston-hidden/extension', '--development']' returned non-zero exit status 1. warnings.warn(msg[-1].strip()) [/myuser/Library/Application](https://file+.vscode-resource.vscode-cdn.net/myuser/Library/Application) Support/hatch/env/virtual/myext/QH3Z3Wb8/myext/lib/python3.10/site-packages/jupyterlab/debuglog.py:56: UserWarning: See the log file for details: [/var/folders/b2/q6kv81b913394cjcw8f2tfkm0000gn/T/jupyterlab-debug-_de99oa9.log](https://file+.vscode-resource.vscode-cdn.net/var/folders/b2/q6kv81b913394cjcw8f2tfkm0000gn/T/jupyterlab-debug-_de99oa9.log) warnings.warn(f"See the log file for details: {log_path!s}") ```

Reproduce

To reproduce it, just install winston and invoke it.

Example

  1. From the extension directory

    jlpm add winston
  2. Use the following as your src/index.js file

    
    import {
    JupyterFrontEnd,
    JupyterFrontEndPlugin
    } from '@jupyterlab/application';

// ------- offending code ------- import * as winston from 'winston'; const logger = winston.createLogger({ level: 'info', transports: [ new winston.transports.Console() ] }); logger.info("Test") // ------- /offending code -------

/**

Expected behavior

The build finish succesfully

E.g.

build-extension-ok

Context

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

fcollonval commented 4 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.