【问题标题】:"module fs cannot be found"“找不到模块 fs”
【发布时间】:2017-07-31 08:54:28
【问题描述】:

我使用了var module = require('/path/to/node_modules/module-name'),我的所有其他型号都得到了识别,但fs 没有得到识别,即使我已经指出它在哪里并确保它已安装??不明白,请帮忙

我的控制台给出了这个: http://prntscr.com/g2akvs

但我所有其他模块都很好

正如您在我的引用中看到的那样: http://prntscr.com/g2akzm

【问题讨论】:

  • fs 是一个原生 nodejs 模块,它应该按原样导入:let fs = require('fs');
  • 试过了,还是不行:/
  • 同样的错误?
  • 是的,我必须删除文件路径并将其更改为 ('fs')
  • 我的意思是说工作*

标签: javascript node.js node-modules


【解决方案1】:

在 node.js 中,fs 是一个原生的内置模块。您将其包含在没有任何路径的情况下,如下所示:

const fs = require('fs');

这是来自node.js source 的内置库列表:

const builtinLibs = [
  'assert', 'async_hooks', 'buffer', 'child_process', 'cluster', 'crypto',
  'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'net', 'os',
  'path', 'punycode', 'querystring', 'readline', 'repl', 'stream',
  'string_decoder', 'tls', 'tty', 'url', 'util', 'v8', 'vm', 'zlib'
];

【讨论】:

    猜你喜欢
    • 2018-07-10
    • 2017-02-12
    • 2017-09-06
    • 2019-06-11
    • 2021-08-22
    • 2021-09-06
    • 2021-07-15
    • 2019-10-19
    • 2022-06-27
    相关资源
    最近更新 更多