Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] 如何在 Vue 组件中使用fs模块? #489

Open
Pandaver opened this issue May 11, 2024 · 12 comments
Open

[Help] 如何在 Vue 组件中使用fs模块? #489

Pandaver opened this issue May 11, 2024 · 12 comments
Labels
help wanted Extra attention is needed

Comments

@Pandaver
Copy link

src\views\Index.vue

<template>
</template>
<script setup lang="ts">
    import { lstat } from 'node:fs/promises'
</script>

electron\main\index.ts
截图_20240512001251

console
截图_20240512001453

求教!

@Pandaver Pandaver added the help wanted Extra attention is needed label May 11, 2024
@Pandaver
Copy link
Author

克隆项目后打开这两个地方,运行也会报错
截图_20240512002020
截图_20240512002037
截图_20240512002134

还需要修改哪里呢?

@RSS1102
Copy link
Member

RSS1102 commented May 15, 2024

node:fs在主进程使用,然后通过通信把数据传到渲染进行。

@Pandaver
Copy link
Author

能提供一个示例嘛
截图_20240516201054
为啥electronjs官网说nodeIntegration启用就可以随便用了

@pengleiwork
Copy link

同问,问题解决了吗

@pengleiwork
Copy link

克隆项目后打开这两个地方,运行也会报错 截图_20240512002020 截图_20240512002037 截图_20240512002134

还需要修改哪里呢?

同问,请问问题解决了吗

@RSS1102
Copy link
Member

RSS1102 commented May 16, 2024

你可以看下这个 https://github.com/caoxiemeihao/electron-vite-samples/tree/main/sqlite3-renderer-process,

serialport-renderer-process/src/main.ts目录尝试使用。

fs.mkdir('file').catch(() => {
  console.log('data directory already exists')
})

@pengleiwork
Copy link

你可以看下这个 https://github.com/caoxiemeihao/electron-vite-samples/tree/main/sqlite3-renderer-process,

在_serialport-renderer-process/src/main.ts_目录尝试使用。

fs.mkdir('file').catch(() => {
  console.log('data directory already exists')
})

你说的这个sqlite3-renderer-process引入fs之类的是没有报错的,但是electron-vite-vue引入就是报错Dynamic require of
"xxx" is not supported,能说下你是怎么修改的吗

@pengleiwork
Copy link

pengleiwork commented May 17, 2024 via email

@palmtoy
Copy link

palmtoy commented May 23, 2024

克隆项目后打开这两个地方,运行也会报错 截图_20240512002020 截图_20240512002037 截图_20240512002134

还需要修改哪里呢?

碰到同样的问题, 按照此方法必然复现该问题, 烦劳开发组关注一下.

node:fs在主进程使用,然后通过通信把数据传到渲染进行。

另外, 按照 "RSS1102"的说法, 是不是就不应该在渲染进程使用 node:fs ?

@JungleHH
Copy link

按照推荐来,不要在渲染进程使用 node:fs
至于Dynamic require is not supported, 这是另一个问题

@Coder-XJ
Copy link

Coder-XJ commented Nov 7, 2024

关闭进程隔离contextIsolation: false,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants