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

Wallaby can't resolve module with require.main.require inside of a node_module #2061

Closed
jljorgenson18 opened this issue May 1, 2019 · 10 comments

Comments

@jljorgenson18
Copy link

I recently just upgraded https://github.com/kisenka/svg-sprite-loader and they started using require.main.require to detect the webpack version. They are attempting to load in the webpack package.json file to then parse the version number. This runs fine if running the tests with mocha via command line, but Wallaby can't find the right Webpack module. I can't think of any solid workaround besides downgrading svg-sprite-loader because this happens in the same process as the Webpack build.

@jljorgenson18
Copy link
Author

Looks like this a problem for other testing libraries so they may fix it on their side JetBrains/svg-sprite-loader#309

However if other modules end up using require.main.require, this would still break Wallaby.

@smcenlly
Copy link
Member

smcenlly commented May 2, 2019

Thanks for reporting this issue. We've updated wallaby to patch require.main paths so that this works correctly in the future. The fix is available in v1.0.681 of wallaby core.

@jljorgenson18
Copy link
Author

Awesome! I can go ahead and close then.

@jljorgenson18
Copy link
Author

@smcenlly I am still seeing this problem on v1.0.688. Seeing this in the logs.

[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Info]  Started Wallaby.js Core v1.0.688
[Info]  Wallaby App (realtime reports) is available at: http://localhost:51245
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error]   `@babel/polyfill` is deprecated. Please, use required parts of `core-js` 
[Error]   and `regenerator-runtime/runtime` separately 
[Error] Runtime error: Uncaught Error: Module build failed (from /Users/jessejorgenson/projects/uno/node_modules/svg-sprite-loader/lib/loader.js): 
[Error] Error: Cannot find module 'webpack/package.json' 
[Error]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15) 
[Error]     at Function.Module._load (internal/modules/cjs/loader.js:475:25) 
[Error]     at Module.require (internal/modules/cjs/loader.js:598:17) 

@jljorgenson18 jljorgenson18 reopened this May 20, 2019
@smcenlly
Copy link
Member

We've just released an update that should fix this for you. Please update to the latest version of core (v1.0.689). If you find that wallaby doesn't automatically update for you after restarting your editor, you can perform a forced update.

@jljorgenson18
Copy link
Author

Still broken on v1.0.689

[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Info]  Started Wallaby.js Core v1.0.689
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error]   `@babel/polyfill` is deprecated. Please, use required parts of `core-js` 
[Error]   and `regenerator-runtime/runtime` separately 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` 
[Error] Runtime error: Uncaught Error: Module build failed (from /Users/jessejorgenson/projects/uno/node_modules/svg-sprite-loader/lib/loader.js): 
[Error] Error: Cannot find module 'webpack/package.json' 
[Error]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15) 
[Error]     at Function.Module._load (internal/modules/cjs/loader.js:475:25) 
[Error]     at Module.require (internal/modules/cjs/loader.js:598:17) 
[Error]     at Object.<anonymous> (/Users/jessejorgenson/projects/uno/node_modules/svg-sprite-loader/lib/utils/get-webpack-version.js:2:37) 
[Error]     at Module._compile (internal/modules/cjs/loader.js:654:30) 
[Error]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) 
[Error]     at Module.load (internal/modules/cjs/loader.js:566:32) 
[Error]     at tryModuleLoad (internal/modules/cjs/loader.js:506:12) 
[Error]     at Function.Module._load (internal/modules/cjs/loader.js:498:3) 
[Error]     at Module.require (internal/modules/cjs/loader.js:598:17) 
[Error]     at require (internal/modules/cjs/helpers.js:11:18) 
[Error]     at Object.<anonymous> (/Users/jessejorgenson/projects/uno/node_modules/svg-sprite-loader/lib/utils/get-module-chunk.js:1:86) 
[Error]     at Module._compile (internal/modules/cjs/loader.js:654:30) 
[Error]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) 
[Error]     at Module.load (internal/modules/cjs/loader.js:566:32) 
[Error]     at tryModuleLoad (internal/modules/cjs/loader.js:506:12) 
[Error]     at Function.Module._load (internal/modules/cjs/loader.js:498:3) 
[Error]     at Module.require (internal/modules/cjs/loader.js:598:17) 
[Error]     at require (internal/modules/cjs/helpers.js:11:18) 
[Error]     at Object.<anonymous> (/Users/jessejorgenson/projects/uno/node_modules/svg-sprite-loader/lib/utils/index.js:6:33) 
[Error]     at Module._compile (internal/modules/cjs/loader.js:654:30) 
[Error]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) 
[Error]     at Module.load (internal/modules/cjs/loader.js:566:32) 
[Error]     at tryModuleLoad (internal/modules/cjs/loader.js:506:12) 
[Error]     at Function.Module._load (internal/modules/cjs/loader.js:498:3) 
[Error]     at Module.require (internal/modules/cjs/loader.js:598:17) 
[Error]     at require (internal/modules/cjs/helpers.js:11:18) 
[Error]     at Object.<anonymous> (/Users/jessejorgenson/projects/uno/node_modules/svg-sprite-loader/lib/configurator.js:3:15) 
[Error]     at Module._compile (internal/modules/cjs/loader.js:654:30) 
[Error]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) 
[Error]     at Module.load (internal/modules/cjs/loader.js:566:32) 

@smcenlly smcenlly reopened this May 21, 2019
@smcenlly
Copy link
Member

It looks like the problem is deeper than what we originally duplicated. Wallaby spawns a number of node worker processes with different contexts and the original fix only addresses one of three contexts.

To unblock you for now while we investigate further, can you please try updating your wallaby.js configuration as detailed below:

// Put this at the top of your wallaby.js file before you import svg-sprite-loader
const path = require('path');
require.main.paths.push(__dirname);
require.main.paths.push(path.join(__dirname, 'node_modules'));
require.main._wallabyPathsAdded = true;

module.exports = function (wallaby) {
    // Put this at the top of your export function
    if (!require.main._wallabyPathsAdded) {
        require.main.paths.push(wallaby.localProjectDir);
        require.main.paths.push(path.join(wallaby.localProjectDir, 'node_modules'));
        require.main._wallabyPathsAdded = true;
    }

...

};

@jljorgenson18
Copy link
Author

I'll be on vacation for two weeks so no worries about a temp workaround. If there is anything I can do to help when I get back, please let me know,

@smcenlly
Copy link
Member

After a bit more investigation, if the workaround works for you, that's going to be our recommendation for handling this particular scenario. Could you please confirm that it's working for you?

@jljorgenson18
Copy link
Author

@smcenlly Just got back and looks like that works! I appreciate the help.

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