Skip to content

vite-typescript template conflict with "allowImportingTsExtensions":true #3499

Closed as not planned

Description

@XLin0mu

Pre-flight checklist

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

Electron Forge version

7.2.0

Electron version

v29.0.0

Operating system

Win10 x64 Pro 22H2 19045.3208

Last known working Electron Forge version

7.2.0

Expected behavior

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies
✔ Running generateAssets hook
......

Actual behavior

✔ Checking your system
✔ Locating application
✖ Loading configuration
› Unable to use specified module loaders for ".ts".
◼ Preparing native dependencies
◼ Running generateAssets hook

An unhandled rejection has occurred inside Forge:
Error: Unable to use specified module loaders for ".ts".
at Object.exports.prepare (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules\rechoir\index.js:58:11)
at exports.default (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules@electron-forge\core\src\util\forge-config.ts:117:17)
at async Task.task (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules@electron-forge\core\src\api\start.ts:63:29)
at async Task.run (C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules\listr2\dist\index.cjs:978:11)
at async C:\Users\XLin0mu\AppData\Roaming\npm\node_modules@electron-forge\cli\node_modules\p-map\index.js:57:22

Steps to reproduce

  1. Execute command npm init electron-app@latest DLR_SA -- --template=vite-typescript.
  2. Add this item to tsconfig.json:
{
"compilerOptions": {
//...
"allowImportingTsExtensions": true,
"noEmit": true,
//whether add "noEmit" at here won't make any different.
//...
}
  1. Run forge start script. npm run start or electron-forge start, givensame error message exclude the path.

Additional information

Full tsconfig.json file (which one make error):

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "commonjs",
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "noImplicitAny": true,
    "sourceMap": true,
    "baseUrl": ".",
    "outDir": "dist",
    "moduleResolution": "node",
    "resolveJsonModule": true,

    "noEmit": true,
    "allowImportingTsExtensions": true,
  },
  "include": ["src"]
}

Activity

  1. jpmckown commented on Mar 2, 2024

    @jpmckown

    Want to share my experience with this error here;

    I was running into the same error Error: Unable to use specified module loaders for ".ts". but I was not using the configuration above. What ended up being the cause was that I had removed ts-node from my package,json. When I put ts-node back the error was resolved and the app started as expected.

  2. aentwist commented on May 6, 2024

    @aentwist

    The expectation here is that your resolver (e.g. your bundler, a runtime, or some other tool) is going to make these imports between .ts files work.

    https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions

    I need tsx for React. React wants a module/bundler setup while forge only works with commonjs/node? So maybe commonjs/node isn't cutting it here? If we can use module/bundler then it will "make these imports between .ts files work".

    A potential workaround might be to nest the React package.json/tsconfig instead of flattening it onto electron so that both can have their own? Not really a fan of this though, nor have I gotten it to work yet.

  3. aentwist commented on May 6, 2024

    @aentwist
    The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
    

    I get that when I run npm run package 😀 (although unrelated??) it shares my sentiment

  4. rtritto commented on May 29, 2024

    @rtritto

    @jpmckown do you use ts-node in the start script, in vite config or somewhere?

  5. jpmckown commented on May 29, 2024

    @jpmckown

    @jpmckown do you use ts-node in the start script, in vite config or somewhere?

    It's been a while but as I recall, ts-node is a dependency for Electron itself. So, the short answer is no, I think. Just leave the scripts as-is when generated by the forge.

  6. rtritto commented on May 29, 2024

    @rtritto

    Thanks, I added ts-node as dev dependency and it worked.

    Edit:
    ts-node should be added as an optional peer dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions