Git Product home page Git Product logo

Comments (5)

nelsonni avatar nelsonni commented on July 4, 2024

If the electron-vite tool begins throwing Cannot write './src/preload/index.d.ts' because it would overwrite input file., then the solution is to add "noEmit": true to compilerOptions in tsconfig.node.json and tsconfig.web.json. This answer was found here: vitejs/vite#13747 (comment)

from synectic.

nelsonni avatar nelsonni commented on July 4, 2024

electron-vite includes pre-populated config files for Electron Builder, which should be removed and migrated into config files for conveyor as part of #1277.

from synectic.

nelsonni avatar nelsonni commented on July 4, 2024

There are two slightly different Electron-Vite sites:

from synectic.

nelsonni avatar nelsonni commented on July 4, 2024

An interesting anecdote from the migration is that as of 1e6bbb5, we are seeing the following error message:

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. ts(7056)

image

Related to reduxjs/redux-toolkit#3591 and Typescript: "The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.", this error occurs when calling createAsyncThunk.withTypes<>(). But it only occurs when "declaration": true is set in the tsconfig.json files.

The electron-vite project provides templates that include the the following compilerOptions:

"compilerOptions": {
"composite": true,
"jsx": "react-jsx",
"noEmit": true,
"baseUrl": ".",
"paths": {
"@renderer/*": ["src/renderer/src/*"]
}
}
}

It is not immediately obvious how this relates to "declaration": true, until looking at the TypeScript tsconfig#composite documentation:

The composite option enforces certain constraints which make it possible for build tools (including TypeScript itself, under --build mode) to quickly determine if a project has been built yet.

When this setting is on:

  • The rootDir setting, if not explicitly set, defaults to the directory containing the tsconfig.json file.

  • All implementation files must be matched by an include pattern or listed in the files array. If this constraint is violated, tsc will inform you which files weren’t specified.

  • declaration defaults to true

This last point is the cause of those "...inferred type of this node exceeds the maximum length the compiler will serialize..." errors, since "composite": true requires "declaration": true. We can fix this issue by removing the following line, in which case "declaration": false is the default:

"composite": true,

from synectic.

nelsonni avatar nelsonni commented on July 4, 2024

Since sindresorhus/find-up is pure ESM only (as of v6.0.0), and ESM support in Electron is not going to be released until Electron 28, we must externalize this dependency in order to prevent it being bundled into a CJS module chunk in Vite. The solution for doing so was found alex8088/electron-vite#35:

preload: {
plugins: [externalizeDepsPlugin({ exclude: ['find-up'] })],
build: {
outDir: 'out/preload',
rollupOptions: {
output: {
manualChunks(id) {
return id.includes('find-up') ? 'find-up' : undefined;
}
}
}
}
},

from synectic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.