teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

誤字修正

2021/09/30 13:22

投稿

iwanao513
iwanao513

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,68 @@
1
1
  Vue+Electronでアプリ開発を行っています。
2
- ファイルの出力を行いたく、require("fs")で呼び出してfs.writeFileをやろうとしたところ
3
- 「fs.writeFile is not a function」
4
- のエラーが出ています。
2
+ ファイル出力を行いたくコードを書いたところ、エラーが出ています。
5
3
 
6
4
  色々調べてみましたがうまくいかないため教えていただきたいです。
7
5
 
8
- 試したこと
6
+
7
+ ### 発生している問題・エラーメッセージ
8
+
9
+ ```
10
+ 「fs.writeFile is not a function」
11
+ ```
12
+
13
+ ### 該当のソースコード
14
+
15
+ ```JS
16
+ <template>
17
+ <div class="header">
18
+ <button type="button" v-on:click="filemake">ファイル作成</button>
19
+
20
+ </div>
21
+
22
+ </template>
23
+
24
+ <script>
25
+
26
+ const fs = require('fs');
27
+ export default {
28
+ name: 'Home',
29
+ components: {
30
+
31
+ },
32
+ data() {
33
+ return {
34
+
35
+ }
36
+ },
37
+ computed:{
38
+
39
+ },
40
+ methods: {
41
+
42
+ filemake(){
43
+ let text = "テスト出力";
44
+
45
+ fs.writeFileSync('out.txt', text, (err) => {
46
+ if(err) console.log(err);
47
+ else console.log('write end');
48
+ });
49
+
50
+
51
+ }
52
+ }
53
+ }
54
+ </script>
55
+ ```
56
+
57
+ ### 試したこと
58
+ ルートディレクトリにvue.config.jsを追加
59
+ [参考ページ](https://www.waguri-soft.com/2020/10/12/vue3-0-electron%E3%81%A7%E3%83%A1%E3%83%A2%E5%B8%B3%E3%83%87%E3%82%B9%E3%82%AF%E3%83%88%E3%83%83%E3%83%97%E3%82%A2%E3%83%97%E3%83%AA%E3%82%92%E4%BD%9C%E3%82%8B/)
60
+ ```JS
61
+ module.exports = {
62
+ pluginOptions: {
63
+ electronBuilder: {
64
+ nodeIntegration: true
65
+ }
66
+ }
67
+ }
68
+ ```