Skip to content

引入electron-fetch会导致报错无法运行 #66

@ifrvn

Description

@ifrvn

init 项目后安装 electron-fetch ,然后在src/main下引入electron-fetch后运行项目就会报错

复现过程

  1. yarn create electron-vue-next 一路默认,然后进入目录执行yarn
  2. yarn add -D electron-fetch
  3. src/main/index.ts中添加如下两行
    import fetch from 'electron-fetch'
    const theFetch = fetch
    
    执行 yarn dev(如果之前有运行过项目,先删除dist目录,否则会使用之前生成的dist/index.js启动窗口,不会弹出报错窗口)

错误信息

> Executing task: yarn run dev <

yarn run v1.22.5
$ node scripts/dev.js
(node:16840) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./dist/" in the "exports" field module resolution of the package at D:\dev\test\node_modules\rollup\package.json.
Update this package.json to use a subpath pattern like "./dist/*".
(Use `node --trace-deprecation ...` to show where the warning was created)
[DEV] Dev server listening on 3031

  vite v2.3.8 dev server running at:

  > Local: http://localhost:8080/
  > Network: use `--host` to expose
{
  code: 'ERROR',
  error: [Error: Could not load D:\dev\test\node_modules\iconv-lite\lib\index.js.ts (imported by D:\dev\test\node_modules\iconv-lite\lib\index.js?commonjs-proxy): ENOENT: no such file or directory, open 'D:\dev\test\node_modules\iconv-lite\lib\index.js.ts'] {     
    errno: -4058,
    code: 'ENOENT',
    syscall: 'open',
    path: 'D:\\dev\\test\\node_modules\\iconv-lite\\lib\\index.js.ts',
    watchFiles: [
      'D:\\dev\\test\\src\\main\\index.dev.ts',
      'vue-devtools',
      'D:\\dev\\test\\src\\main\\index.ts',
      'D:\\dev\\test\\static/logo.png?static',
      'D:\\dev\\test\\src\\renderer/index.html?renderer',
      'D:\\dev\\test\\src\\renderer/side.html?renderer',
      'D:\\dev\\test\\src\\preload/index?preload',
      'D:\\dev\\test\\src\\preload/another?preload',
      'D:\\dev\\test\\src\\main\\logger.ts',
      'D:\\dev\\test\\src\\main\\dialog.ts',
      'D:\\dev\\test\\src\\main\\services\\index.ts',
      'D:\\dev\\test\\src\\preload\\index.ts',
      'D:\\dev\\test\\src\\preload\\another.ts',
      'D:\\dev\\test\\src\\main\\services\\BaseService.ts',
      'D:\\dev\\test\\src\\main\\services\\Service.ts',
      'D:\\dev\\test\\src\\main\\services\\FooService.ts',
      'D:\\dev\\test\\src\\shared\\sharedLib.ts',
      'D:\\dev\\test\\node_modules\\electron-fetch\\lib\\index.es.js',
      'D:\\dev\\test\\node_modules\\encoding\\lib\\encoding.js',
      '\x00commonjsHelpers.js.ts',
      '\x00D:\\dev\\test\\node_modules\\encoding\\lib\\encoding.js?commonjs-exports',
      'D:\\dev\\test\\node_modules\\iconv-lite\\lib\\index.js',
      '\x00D:\\dev\\test\\node_modules\\iconv-lite\\lib\\index.js?commonjs-proxy',
      '\x00D:\\dev\\test\\node_modules\\iconv-lite\\lib\\index.js?commonjs-module',
      '\x00stream?commonjs-external',
      'D:\\dev\\test\\node_modules\\iconv-lite\\lib\\index.js.ts'
    ]
  },
  result: null
}
[DEV] Electron app started
[DEV] Skip start/reload preload.

[CONSOLE] Debugger listening on ws://127.0.0.1:5858/a5f5bdcd-4ebc-4ced-97fb-e851cc7baee6[CONSOLE] For help, see: https://nodejs.org/en/docs/inspector

image

环境信息

Windows 10 x64
node v16.3.0
yarn 1.22.5
electron-vue-next commit/eeeb5748e7b9756414da304242dbf71ee31f63a8
electron-fetch ^1.7.3

# .yarnrc
registry "https://registry.npm.taobao.org"
electron_mirror "https://npm.taobao.org/mirrors/electron/"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions