question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: cannot find module undefinedbuild/... after HMR

See original GitHub issue

Preflight Checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Issue Details

Durig development after hot reloading the app, the following error occurs:

Uncaught Error: Cannot find module 'undefinedbuild/Release/better_sqlite3.node'
Require stack:
- electron/js2c/renderer_init
    at Module._resolveFilename (internal/modules/cjs/loader.js:887)
    at Function.o._resolveFilename (electron/js2c/renderer_init.js:33)
    at Module._load (internal/modules/cjs/loader.js:732)
    at Function.f._load (electron/js2c/asar_bundle.js:5)
    at Function.o._load (electron/js2c/renderer_init.js:33)
    at Module.require (internal/modules/cjs/loader.js:959)
    at require (internal/modules/cjs/helpers.js:88)
    at eval (database.js?4c26:9)
    at Object../node_modules/better-sqlite3/lib/database.js (index.js:66025)
    at __webpack_require__ (index.js:78100)

better_sqlite3 is a native module and is built with electron-rebuild during install with a script in package.json:

"postinstall": "electron-rebuild -f -w better-sqlite3",

For HMR I’m using react-hot-loader.

  • Electron Forge Version:
    • 6.0.0-beta.59
  • Electron Version:
    • 13.1.7
  • Operating System:
    • Windows 10
    • Ubuntu 12.04 x64
  • Last Known Working Electron Forge version::
    • 6.0.0-beta.57

Expected Behavior

The app should reload correctly.

Actual Behavior

The error appears in the console and the screen keeps blank.

To Reproduce

Additional Information

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
Nestorocommented, Mar 8, 2022
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const relocateLoader = require('@vercel/webpack-asset-relocator-loader');

module.exports = [
  new ForkTsCheckerWebpackPlugin(),
  // modification below
  {
    apply(compiler) {
      compiler.hooks.compilation.tap('webpack-asset-relocator-loader', (compilation) => {
        relocateLoader.initAssetCache(compilation, 'native_modules');
      });
    },
  },
];

with this webpack.plugins.js it works!

3reactions
florianbepunktcommented, Jan 15, 2022

Nevermind, just missed to configure the path correctly. For anyone else

const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const relocateLoader = require('@vercel/webpack-asset-relocator-loader');

module.exports = [
  new ForkTsCheckerWebpackPlugin(),
  new NodePolyfillPlugin(),
  new CircularDependencyPlugin({
    // exclude detection of files based on a RegExp
    exclude: /a\.js|node_modules/,
    // include specific files based on a RegExp
    // add errors to webpack instead of warnings
    failOnError: true,
    // allow import cycles that include an asyncronous import,
    // e.g. via import(/* webpackMode: "weak" */ './file.js')
    allowAsyncCycles: false,
    // set the current working directory for displaying module paths
    cwd: process.cwd(),
  }),
  // modification below
  {
    apply(compiler) {
      compiler.hooks.compilation.tap('webpack-asset-relocator-loader', (compilation) => {
        relocateLoader.initAssetCache(compilation, 'native_modules');
      });
    },
  },
];

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: cannot find module undefinedbuild/... after HMR #2412
Issue Details. Durig development after hot reloading the app, the following error occurs: Uncaught Error: Cannot find module 'undefinedbuild/ ...
Read more >
electron-forge package Error: Cannot find module
I am trying to run the packaged electron app on my local Mac. But get an error message saying Error: Cannot find module...
Read more >
react-native-windows/CHANGELOG.json - UNPKG
The CDN for react-native-windows.
Read more >
Import.meta.env undefined on production build vitejs-Reactjs
Nextjs fails to find valid build in the '.next' directory in production ... Syntax error: Cannot read property 'map' of undefined (0:undefined) build...
Read more >
r/nextjs - Reddit
NextJS throws random "Error: Cannot find module './undefined'". I just encountered this error while navigating to different links using NextJs's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found