Open simulieren opened 4 years ago
Edit: This comment was a mistake on my side. Webpack was using an old .js
file in dist.
Well, I've just accidentally found a fix ...
Having ./electron/main/index.js
next to the ./electron/main/index.ts
file makes it somehow work. The index.js
can be completely empty and the code in the .ts
file will run. But the type checking seems to be off and I get this error:
Module parse failed: The keyword 'interface' is reserved (98:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
I don't think this is the expected behavior but it solved my issue. Hope this helps to get to the real solution.
Okay, I've found a workaround for TS support. I'm running tsc -w
in another folder during my development.
The electron folder now has this folder structure:
├── main
│ └── index.js
├── src
│ ├── index.ts
│ └── tsconfig.json
My tsconfig.json
looks like this:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"jsx": "react-native",
"moduleResolution": "node",
"target": "ESNext",
"noEmit": false,
"skipLibCheck": true,
"listEmittedFiles": true,
"outDir": "../main",
"rootDir": "."
},
"files": [
"index.ts"
],
"exclude": [
"*.tsx",
"../src/**/*",
]
}
Okay, I've found a workaround for TS support. I'm running
tsc -w
in another folder during my development.The electron folder now has this folder structure:
├── main │ └── index.js ├── src │ ├── index.ts │ └── tsconfig.json
My
tsconfig.json
looks like this:{ "compilerOptions": { "allowSyntheticDefaultImports": true, "experimentalDecorators": true, "jsx": "react-native", "moduleResolution": "node", "target": "ESNext", "noEmit": false, "skipLibCheck": true, "listEmittedFiles": true, "outDir": "../main", "rootDir": "." }, "files": [ "index.ts" ], "exclude": [ "*.tsx", "../src/**/*", ] }
This is an obvious way to compile typescript, but can it be done with webpack during runtime? I tried pushing ts-loader into webpack config rules, but it tries to compile .tsx files from app itself, not electron backend:
ERROR in ./App.tsx
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /App.tsx
Description
I'm trying to get TypeScript working for the main process of Electron. I've tried the addon
electron-webpack-ts
fromelectron-webpack
and it isn't working properly. The webpack configuration ignores it and chooses the default template.Expected Behavior
The webpack configuration should recognize
.ts
files in./electron/main/
and create a build into the./dist/main
folder.Observed Behavior
As soon as I convert the files in
./electron/main/
to.ts
the webpack configuration defaults back to the template files in@expo/electron-adapter/template/electron/main.js
.No error messages.
This is the webpack log with the wrong entry point:
Environment
Reproducible Demo
Repo with the setup: https://github.com/simulieren/expo-electron-ts-issue