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

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

Closed
3 tasks done
atheck opened this issue Jul 28, 2021 · 11 comments
Closed
3 tasks done

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

atheck opened this issue Jul 28, 2021 · 11 comments
Labels
bug help wanted plugin/webpack Issues or pull requests related to first-party webpack plugins/templates

Comments

@atheck
Copy link

atheck commented Jul 28, 2021

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

@atheck atheck added the bug label Jul 28, 2021
@malept malept added help wanted plugin/webpack Issues or pull requests related to first-party webpack plugins/templates labels Jul 28, 2021
@ldevalliere
Copy link

ldevalliere commented Aug 26, 2021

Also ran into this hot reload issue with a native module. I made a quick example: https://github.com/ldevalliere/temp-electron-forge where if you run it and then make a small change to trigger a hot reload you'll get the issue Uncaught Error: Cannot find module 'undefinedbuild/Release/drivelist.node' in the console. And note that you won't get this error if you simply refresh.
Screen Shot 2021-08-26 at 9 29 39 PM

@Quelu
Copy link

Quelu commented Oct 7, 2021

I had the same issue with the node-keytar native module on 6.0.0-beta.61.

@atheck
Copy link
Author

atheck commented Nov 25, 2021

I finally found a workaround for this. I no longer use the @vercel/webpack-asset-relocator-loader in development mode.

webpack.rules.js

const nodeLoaderRule = {
    test: /native_modules\/.+\.node$/u,
    use: "node-loader",
};
const relocatorRule = {
    test: /\.(m?js|node)$/u,
    parser: { amd: false },
    use: {
        loader: "@vercel/webpack-asset-relocator-loader",
        options: {
            outputAssetBase: "native_modules",
        },
    },
};
const tsLoaderRule = {
    test: /\.tsx?$/u,
    exclude: /(node_modules|\.webpack)/u,
    use: {
        loader: "ts-loader",
        options: {
            transpileOnly: true,
        },
    },
};

if (process.env.BUILD_PRODUCTION) {
    module.exports = [nodeLoaderRule, relocatorRule, tsLoaderRule];
} else {
    module.exports = [nodeLoaderRule, tsLoaderRule];
}

webpack.plugins.js

const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");

let copyPatterns;

if (process.env.BUILD_PRODUCTION) {
    copyPatterns = [];
} else {
    copyPatterns = [
        {
            // Workaround: Copy native_modules in some directory where it's found
            from: path.resolve(__dirname, "native_modules/build"),
            to: path.resolve(__dirname, "out/"),
        },
    ];
}

module.exports = [
    new ForkTsCheckerWebpackPlugin(),
    new CopyWebpackPlugin({
        patterns: copyPatterns,
    }),
];

@MynockSpit
Copy link

Seems like this is related to webpack 5 caching, and should be fixable like this. We should consider adding that as a default parameter during development mode.

@atheck
Copy link
Author

atheck commented Nov 30, 2021

@MynockSpit it seems to work. Thank you a lot.

@florianbepunkt
Copy link

@MynockSpit @atheck Could you please provide more details how to fix this?

@florianbepunkt
Copy link

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');
      });
    },
  },
];

@Nestoro
Copy link

Nestoro commented 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!

Jbithell added a commit to Paradise-Pi/ParadisePi that referenced this issue Apr 24, 2022
quolpr added a commit to kikko-land/kikko-electron-better-sqlite3-example that referenced this issue Jun 29, 2022
Jbithell added a commit to Paradise-Pi/ParadisePi that referenced this issue Jul 9, 2022
* Add docs site

* Add barebones typescript

* Attempt to catch out databases that end up in the wrong directory

* Add basic docs

* Ignore datagrip's files

* Add typeorm config, models and migrations

* Fix json file typo

* Document testing tools

* Add e131 to global scope

* Update createMainWindow.ts

* Add author

* Move migrations

* Update .gitignore

* Remove cache to fix electron/forge#2412

* Get a working build

* Swap tailwind for mantine

* Tweak nav

* Experiment with buttons

* Adda bout

* Add dark background

* Expose webpack build in development

* Add admin site to webpack

* Fix migrations

* Clear out v1 files

* Add QR Code package

* Ignore all databases

* Fix icon path

* Fix icon path

* Add a second nav class

* Add prettier and lint

* Fix docusaurus error

* Bump docusaurus

* Add API via both contextbridge and sockets

* Demonstrate working refresh function with redux

* Build out admin interface and include CPU & Ram usage

* Tidy up visuals of control page

* Migrate to some new, more sensible, models. Includes migrations tested against dramasoc, lounge & blank db

* Move to our own fork of the e131 lib

* Add E131 fading (#21)

* Add basic e131 fade function

* Change function to allow multiple fades at once

* Add preset management

* Fix crash bug

* Populate list of presets

* Bump codeql version

* Move markdown docs amongst the code

* Move docs around, and add mermaid

* Fix repo path

* Style tweaks

* Tweak into an npm monorepo

* Simplify docs offering again

* Add winston

* Refactor use of get presets route to rely on redux

* Add connection lost and screensaver messages

* Fix sorting

* Add bundle size analyser

* Add list of socket clients

* Fix paths

* Fix capitalisation

* Add clients list to admin interface

* Reduce huge fontawesome bundle size

* Disable analyzer mode as it's breaking github actions

* Add clients list

* Add working general config

* Remove file backup because it fails if no database exists

* Get E1.31 output working

* Add warning about saving risk of config

* OSC output (#22)

* Add V1 osc code as ts

* Add inheritance for osc

* Tidy osc a bit

Co-authored-by: James Bithell <[email protected]>

* Run prettier

* Finish OSC Config and E1.31 Config

Co-Authored-By: John Cherry <[email protected]>

* Force LF line endings

* Fix case sensitivity issue

* Add route for OSC Messages

* Check alternative ports when booting

* Catch being unable to test ports

* Change to a lib with TS support

* Document environment variables

* Set custom port in display

* Few fixes

* Get debugger working

* Add folder admin

* Fix folder sorting

* Add basics of preset settings + add folder help text

* Add input for e1.31

* Implement HTTP & Macro presets

* Add e131 sampler (#25)

* Convert sampler code to typescript

* Broken sampling code but has a nice button

* Move e131 to TS + tidy bits

* Fix restart issue

* Fix IP info

* Add a screen

* Fix breaking changes

Co-authored-by: James Bithell <[email protected]>

* Tweak text

* Add reboot & quit functionality + add e131 sampling socket connection

Co-Authored-By: John Cherry <[email protected]>

* Config page tweaks for saving

* Add restore from backup function

* Improve new db upload UI

* Add live logging into admin

* Only open dev tools if running in dev

* Send a 200 for the backup restore

* Add v1 history page

* Update index.ts

* Fix upload path

* Get file uploads working

* Add edit handling for new databases

* Add basic docs outline

* Add

* OSC Admin Page (#27)

* Add default preset states

* Add form fields

* Tweak for saving

* Make osc presets work

* get current console

Co-authored-by: John Cherry <[email protected]>
Co-authored-by: John Cherry <[email protected]>

* Add LX Keypad to V2 (#28)

* Add keypad and attempt to make communicate

* setintensity

* Correct api and add interface

* remove useRef

* Fix clear logic

* Fix routing and make linking macros

* Add Channel Check mode (#29)

* Tweak menu bar selection system (use url not a state tracked)

* Update reviewdog.yml

* Update Preset.tsx

* Update Help.tsx

* Tweak fader setup to not just restrict to channels

* Rename Preset Folders to Folders because they're now a big core part of the project (not just a little bolt on)

* Fix plural

* Update 1656679151854-AddFaderType.ts

* New table styling, add fader editing, bugfix of invalid json causing crash

Co-Authored-By: John Cherry <[email protected]>

* Pull OSC mixer directly from the reducer

* Add spellings and update packages

* Fix usage rings bug

* Fix OSC edit midas bug

* Improve editing experience in admin

* Remove class as it prevented dbToPercentage being used

* Add fader display + rough in datastore that powers it and metering

* Add fader channel values & metering

* Add fader control

* Fix "Payload not sent" error because a 0 value is falsy

* Remove local port to get dynamically allocated one

Co-Authored-By: John Cherry <[email protected]>

* Remove DCAs as their paths are odd

* Working faders!

* Update faders when a preset is recalled

* V2 Error Boundary (#34)

* Add a simple error boundary

* Remove logger

* comment component

* Get fader positions when preset triggered

* Document V2 (#31)

Add control panel info

* Add QR code to error boundary

* Bump docusaurus

* Change modal to tooltip

* Add a message if audio disconnected and faders can't be shown

* V2 fix osc editor and command encoding (#36)

* check if we have a value before adding to address

* convert to command-based second options

* Add reload button to error boundary

* Spelling

* show JSON editor when our osc editor errors

* use JSON editor as soon as Schema invalid

* support simple OSC messages

* Add logo screensaver functionality

* Lint

* Add fullscreen checkbox

Co-authored-by: John Cherry <[email protected]>
Co-authored-by: John Cherry <[email protected]>
@georgexu99
Copy link
Contributor

closed with electron-forge/electron-forge-docs#76

@Jbithell
Copy link

closed with electron-forge/electron-forge-docs#76

@georgexu99 how should this be approached in typescript? error TS7006: Parameter 'compiler' implicitly has an 'any' type.

@Jbithell
Copy link

Jbithell commented Jun 3, 2023

closed with electron-forge/electron-forge-docs#76

@georgexu99 how should this be approached in typescript? error TS7006: Parameter 'compiler' implicitly has an 'any' type.

Using an explicit any for now

{
  apply(compiler: any) {
	  compiler.hooks.compilation.tap('webpack-asset-relocator-loader', (compilation: any) => {
		  relocateLoader.initAssetCache(compilation, 'native_modules')
	  })
  },
}

Jbithell added a commit to Paradise-Pi/ParadisePi that referenced this issue Jun 16, 2023
cherry-john pushed a commit to Paradise-Pi/ParadisePi that referenced this issue Jul 14, 2023
* bump

* TS Docs aren't actually provided as far as I can see

* Bump

* Add database structure

* Add edit page

* Add config option to macro preset

* Allow presets to be recalled over http

* Bump version

* Improve locked message, and fix logic error in web server

* Basic work on time clock triggers

* Remove time clock triggers

* Lint

* Remove stats file

* Lint

* Update folder.ts

* Add badge showing preset type

* Add parent name to folders

* Add duplicate preset button

* Refactor folder icons to allow them to be used with other buttons

* Add preset icons, and make icons searchable

* Add more icons

* Improve admin pin entry

* Update settings.json

* Start UI

* Bump

* Fix imports

* Add more ui

* Remove webpack cache to fix database error in electron/forge#2412 (comment)

* Radically simplify icon file

* Basic UI

* UI tweaks

* Edit functionality complete

* Build out function

* Update NavbarItem.tsx

* Fix bugs

* Time clock trigger bugfixes

* Clarify skip behaviour

* Lint

* Closes #164 by removing effect mode

* Update index.ts

* Add error handling to sampling mode

* Add docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted plugin/webpack Issues or pull requests related to first-party webpack plugins/templates
Projects
None yet
Development

No branches or pull requests

9 participants