更新时间:2021-12-08 06:31:24
看起来你在你的 index 中调用了
文件.我不确定您在什么上下文中调用该方法,但这看起来像是对服务器端方法的客户端调用.我最近遇到了类似的问题.fs
file-exists
方法.js
It looks like you're calling the fs
file-exists
method in your index.js
file. I'm not sure in what context you're calling the method, but this looks like a client-side call to a server-side method. I ran into a similar issue just recently.
据我了解,主要问题似乎是您无法在浏览器解释的客户端(前端)代码中调用服务器端(节点)方法.您必须从服务器调用它们.
From what I understand, the main issue seems to be that you can't call server-side (Node) methods in browser-interpreted client-side (front end) code. You have to call them from a server.
Webpack 可以将 fs
模块代码加载到您的前端,但浏览器实际上无法解释这些 Node 方法并运行它们;只有 Node 环境可以做到这一点.(更多在这里)
Webpack can load the fs
module code into your front end, but the browser can't actually interpret those Node methods and run them; only a Node environment can do that. (more here)
您可以通过修改对 fs
方法的调用以在服务器端某处发生,或者通过查找提供与 fs 相同功能的等效浏览器支持包来解决核心问题
您需要的方法,但可以在浏览器中运行.
You could fix the core issue by modifying the call to fs
methods to happen somewhere server-side, or by finding an equivalent browser-supported package that offers the same functionality as the fs
methods you need but that can be run in a browser.
快速搜索浏览器的 fs 模块"会显示各种可能满足您需求的选项,例如 fs-web、browserify-fs 或
A quick search for "fs module for browser" brings up a variety of options that might work for what you need, like fs-web, browserify-fs or filer.
这是一个类似的问题,但有一些见解.在 React.js,node.js 中使用 fs 模块.js、webpack、babel、express
Here is a similar question with some insight. Use fs module in React.js,node.js, webpack, babel,express