Describe the bug
When using Axios or Request (or some other modules that doesn't have .ts files), it looks like TS (and/or Electron) doesn't want to resolve modules with .js files and expect .ts file extension.
To reproduce
vue-cli-plugin-electron-builder.yarn add request or yarn add axios.background.ts:import request from 'request';
// OR
import axios from 'axios';
// try to call the imported module, in this case axios:
console.log(axios);
yarn serve:electron.Bundling main process step.Expected behavior
Should properly import modules.
Screenshots
No screenshots so I'm putting logs:
./node_modules/axios/index.js
Module not found:
Error: Can't resolve './lib/axios' in '/Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios'
resolve './lib/axios' in '/Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios'
using description file: /Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios/package.json (relative path: .)
using description file: /Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios/package.json (relative path: ./lib/axios)
no extension /Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios/lib/axios doesn't exist .ts
/Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios/lib/axios.ts doesn't exist
as directory /Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios/lib/axios doesn't exist
[/Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios/lib/axios]
[/Users/totominc/Desktop/Git/poe-mapper-tracker/node_modules/axios/lib/axios.ts]
@ ./node_modules/axios/index.js 1:17-39
@ ./src/background.ts
@ multi ./src/background.ts'
Environment:
import-error)After some research, it looks like the issue come from the webpack configuration. I came across multiple SO/GitHub issues talking about editing resolve#extensions from webpack config.
This one for example, which is exactly the same error as I have.
EDIT: after tweaking the webpack config file and changing the orders of resolve extensions, it still doesn't work.
// vue.config.js on the root of the project
module.exports = {
chainWebpack: config => {
config.resolve.extensions
.clear()
.add('.ts')
.add('.tsx')
.add('.js')
.add('.vue')
.add('.json')
}
}
EDIT 2: I have tried so much things but nothing is working:
vue.config.js (passing config with configureWebpack or pluginOptions#electronBuilder) and following advices from here.rm -rf ./node_modules and regen it with yarn (and repeat with npm).tsconfig.json: jsx, module/target, baseUrl, include/exclude, moduleResolution, sourceMap.vue inspect > vue.wp.js and checking the default config.node_modules/axios, but everything seems fine here.At this point, I'm out of ideas and don't know what to do. This is very blocking for my project and I can't do anything.
EDIT 3: I tried to downgrade vcp-electron-builder to 0.3.2 and re-invoke it. Everything seems to work well so there is something definitely wrong with beta versions IMO. By default it generates an Electron main process file in .js, I switched it to a .ts.
Link to the branch of my repo with [email protected].
EDIT 4: It happened again while I was exporting 2 interfaces and a function from a file into an index.ts. It worked well until I added the 2 interfaces into the index.ts. The issue seems to be that it can't resolve indexes files that have more than 1 exported value. I have not tested a lot of things about it.
馃憤 Would love eyes on this
The issue was that the resolve extensions didn't contain '.js'. This is fixed and you can switch back to the beta with version 1.0.0-beta.6 when it comes out.
Thanks for the fix @nklayman, any ETA for the 1.0.0-beta.6?
It will be released within a few days. If you want to use it now, just set the version of vcp-electron-builder to nklayman/vue-cli-plugin-electron-builder to use the github repo instead of published version.
Beta.6 has just been released, you can use that now!
Works fine, it can now resolve .js index files from node_modules.
Hi, I'm experiencing similar issue but for .json file which from a npm module called spinnies. Is there any workaround for this?
Thanks in advance.
@beeing Try this:
// vue.config.js on the root of the project
module.exports = {
chainWebpack: config => {
config.resolve.extensions.add('.json')
}
}