找不到模块"fs".使用simple-json-loader [英] Cannot find module "fs". Using simple-json-loader
问题描述
我尝试使用simple-json-loader
.我从npm安装此文件并编写以下功能:
I'm try to use simple-json-loader
. I install this from npm and write following function:
onclickExport() {
var loader = require('simple-json-loader');
var json = loader.JSONLoader.loadFromFile('wwwroot/dist/data/files.json');
}
一切似乎都很简单,但是当我在webback中运行build时,我看到以下错误:
Еverything seems simple, but when I run build in webback i see following error:
./〜/simple-json-loader/index.js中的错误 找不到模块:错误:无法在D:\ GitRepo \ Magazine \ Magazine.Web \ node_modules \ simple-json-loader中解析模块'fs' @ ./~/simple-json-loader/index.js
ERROR in ./~/simple-json-loader/index.js Module not found: Error: Cannot resolve module 'fs' in D:\GitRepo\Magazine\Magazine.Web\node_modules\simple-json-loader @ ./~/simple-json-loader/index.js
Npm软件包通过有效路径位于node_modules中.我在那里看到. 另外,在调试此功能时,我会看到类似的错误. 有什么主意为什么行不通吗?
Npm package is in the node_modules by valid path. I see it there. Also In debugging of this function i see analogous error. Is any ideas why it is not work?
推荐答案
听起来像问题在于模块simple-json-loader
依赖于内置的Node模块fs
. fs
是执行各种文件加载和文件系统任务的模块.
It sounds like the issue is that the module simple-json-loader
is reliant on the built-in Node module fs
. fs
is a module that performs various file-loading and file system tasks.
由于看起来您是在Angular2(这是一个前端(客户端)Javascript框架)中构建的,因此这可能是环境问题.
Since it looks like you're building in Angular2, which is a front-end (client-side) Javascript framework, this may be an environment issue.
客户端浏览器环境无法解释和运行某些像fs
这样的Node模块,这些模块是在服务器端Node环境中运行的. (更多)
It's not possible for the client-side browser environment to interpret and run some Node modules like fs
that are built to be run in a server-side Node environment. (more here)
解决方案是在节点环境中在服务器端运行simple-json-loader
模块,或查找具有相同功能但为浏览器编写的软件包.
The solution is to run the simple-json-loader
module server-side in a Node environment or to find a package which offers the same functionality but written for the browser.
在此问题中进行了讨论... 找不到模块:错误:无法解析模块"fs"
It's discussed in this question... Module not found: Error: Cannot resolve module 'fs'
这个问题... 在React.js节点中使用fs模块. js,webpack,babel,express
这篇关于找不到模块"fs".使用simple-json-loader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!