fs.readFileSync is not a function Meteor, React

后端 未结 3 2089
栀梦
栀梦 2020-12-18 05:31

I\'m getting a \'fs.readFileSync is not a function\' in Chrome debugger after trying to call readFileSync();

I call it...

const fs = require(\'fs\')         


        
3条回答
  •  情深已故
    2020-12-18 06:00

    fs cannot be used on the client, due to browsers restricting some javascript code.

    If your code is being run on both the server and client, you can use:

    if (Meteor.isClient) return;
    

    to avoid the error. Otherwise, there should be another way to do what you're trying to accomplish, such as importing required JSON.

提交回复
热议问题