React Js require 'fs'

前端 未结 2 373
悲&欢浪女
悲&欢浪女 2020-12-17 10:46

I have

import fs from \'fs\'

and in my package.json I have

Then I run the command

相关标签:
2条回答
  • 2020-12-17 11:17

    In create-react-app they have stubbed out 'fs'. You cannot import it. They did this because fs is a node core module.
    You'll have to find another solution to that problem. See this ticket.

    0 讨论(0)
  • 2020-12-17 11:28

    It's possible this might be an environment issue. It's not possible for the browser to interpret and run some Node server-side modules like fs.

    The solution is to run the fs methods in a Node environment (server-side) or to find a package which offers the same functionality but written for the browser.

    It's discussed in this question... Module not found: Error: Cannot resolve module 'fs'

    And this question... Use fs module in React.js,node.js, webpack, babel,express

    0 讨论(0)
提交回复
热议问题