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

build: switch from ts-node to esbuild-register #3579

Closed

Conversation

dsanders11
Copy link

Fixes #3568. ts-node is having issues working with the latest versions of Node.js - since this repo is using transpile-only mode anyway, switch to esbuild-register which isn't having those issues.

@1111mp
Copy link

1111mp commented Jan 24, 2024

NODE_OPTIONS should also be set for the webpack command when executing it:

"scripts": {
  // ...
  "start:preload": "cross-env NODE_ENV=development NODE_OPTIONS=\"-r esbuild-register\" webpack --config ./.erb/configs/webpack.config.preload.dev.ts",
  "start:renderer": "cross-env NODE_ENV=development NODE_OPTIONS=\"-r esbuild-register\" webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts",
  // ...
},

If not set, an error will occur when electron is lower than 28.0.0:

$ node -r esbuild-register ./.erb/scripts/check-port-in-use.js && npm run start:renderer

> [email protected] start:renderer
> cross-env NODE_ENV=development webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts

[webpack-cli] Failed to load '/Users/******/Documents/Electron/nvm-desktop/.erb/configs/webpack.config.renderer.dev.ts' config
[webpack-cli] /Users/******/Documents/Electron/nvm-desktop/.erb/scripts/check-node-env.js:1
import chalk from 'chalk';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1153:20)
    at Module._compile (node:internal/modules/cjs/loader:1205:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at extensions..js (/Users/******/Documents/Electron/nvm-desktop/node_modules/esbuild-register/dist/node.js:4838:24)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (/Users/******/Documents/Electron/nvm-desktop/.erb/configs/webpack.config.renderer.dev.ts:12:26)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The release/app/package.json file also needs to be changed.

Thank you for your work. 🌹

"start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts",
"start": "node -r esbuild-register ./.erb/scripts/check-port-in-use.js && npm run start:renderer",
"start:main": "cross-env NODE_ENV=development NODE_OPTIONS=\"--loader esbuild-register/loader -r esbuild-register\" electronmon .",
"start:preload": "cross-env NODE_ENV=development webpack --config ./.erb/configs/webpack.config.preload.dev.ts",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it wasn't enough to leave this as-is; instead I had to add the NODE_OPTIONS=\"--loader esbuild-register/loader -r esbuild-register\" here as well (basically anywhere webpack was called). But this may be due to my fork which has already deviated from this project.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I realize this is the same comment as #3579 (comment).

And yes, release/app/package.json also requires changes!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slhck thanks for the input. I did the same changes & it worked for me with electron version 28.

@dsanders11
Copy link
Author

Closing as this isn't fully baked (switching to esbuild might cause other differences/problems).

@dsanders11 dsanders11 closed this Feb 5, 2024
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

Successfully merging this pull request may close these issues.

Electron 28 breaks build: ERR_UNKNOWN_FILE_EXTENSION – Unknown file extension ".ts" for …
4 participants