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

Plugin is not working in vue js #140

Open
sadashivm opened this issue Dec 4, 2020 · 5 comments
Open

Plugin is not working in vue js #140

sadashivm opened this issue Dec 4, 2020 · 5 comments

Comments

@sadashivm
Copy link

sadashivm commented Dec 4, 2020

Hello,
Im trying to read/write json file, but it is not working, Im getting below error.

image

image

image

image

I Kept data.json same path where App.vue is exist.

@RyanZim
Copy link
Collaborator

RyanZim commented Dec 4, 2020

jsonfile is not for use in the browser; only in Node or Electron.

@RyanZim RyanZim closed this as completed Dec 4, 2020
@sadashivm
Copy link
Author

sadashivm commented Dec 7, 2020

Thanks for the reply @RyanZim ,

I'm using this plugin with Electron only. I got the below error,
image

Here is my code,

image

NOTE: Book.js and data.json files are in the same folder and I have used react js for coding.

@RyanZim
Copy link
Collaborator

RyanZim commented Dec 8, 2020

OK, what bundler are you using? Webpack? Does importing fs directly and using writeFile work?

@sadashivm
Copy link
Author

sadashivm commented Dec 9, 2020

OK, what bundler are you using? Webpack? Does importing fs directly and using writeFile work?

@RyanZim ,
Where should I know which bundler I'm using? I don't know exactly.
here is my package.json file,

package.json

{
  "name": "test-electron-app",
  "version": "0.1.0",
  "description": "Test App",
  "author": "sadashiv",
  "main": "public/electron.js",
  "build": {
    "appId": "com.test-electron-app"
  },
  "homepage": "./",
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.2.2",
    "@tinymce/tinymce-react": "^3.8.1",
    "bootstrap": "^4.5.3",
    "cross-env": "^7.0.2",
    "electron-is-dev": "^1.2.0",
    "jsonfile": "^6.1.0",
    "node-sass": "^4.14.1",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-bootstrap-icons": "^1.1.0",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.1",
    "smooth-scrollbar": "^8.5.3",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "react-start": "react-scripts start",
    "react-build": "react-scripts build",
    "react-test": "react-scripts test",
    "react-eject": "react-scripts eject",
    "electron-build": "electron-builder",
    "build": "npm run react-build && npm run electron-build",
    "start": "concurrently \"cross-env BROWSER=none npm run react-start\" \"wait-on http://localhost:3000 && electron .\""
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "concurrently": "^5.3.0",
    "electron": "^11.0.3",
    "electron-builder": "^22.9.1",
    "wait-on": "^5.2.0"
  }
}

Can I use ur plugin in development mode?
Will it work?

Can you please tel steps to how to use ur npm package with electron and reactjs ?

@RyanZim
Copy link
Collaborator

RyanZim commented Dec 10, 2020

Ah, you're using react-scripts, which uses webpack under the hood.

Comment out your usage of jsonfile, and put this somewhere in your code:

import fs from 'fs';
fs.writeFile('test.txt', 'Hello World!', (err) => {
  if (err) console.error(err);
});

Run your app, see if you get an error, and if the file test.txt is created with contents Hello World!. Let me know what happens; then we can debug from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants