简体   繁体   English

用JSPM运行`fs.writeFile`

[英]Running `fs.writeFile` with JSPM

I'm trying to use Node's fs through jspm . 我正在尝试通过jspm使用Node的fs After having installed fs with jspm install fs , I'm trying to use the writeFile method. 无需安装后fsjspm install fs ,我试图使用writeFile方法。 I'm getting an error. 我遇到错误了。

Uncaught (in promise) TypeError: fs.writeFile is not a function

When I log fs to the console, I see that it only has one method. 当我将fs登录到控制台时,我看到它只有一种方法。

在此处输入图片说明


main.js main.js

import fs from 'fs';
console.log(fs);

Why is fs only showing one available method? 为什么fs仅显示一种可用方法?

readFileSync is the only function supported. readFileSync是唯一受支持的功能。 The entire module is only has that one function: 整个模块只有一个功能:

exports.readFileSync = function(address) {
  var output;
  var xhr = new XMLHttpRequest();
  xhr.open('GET', address, false);
  xhr.onreadystatechange = function(e) {
    if (xhr.readyState == 4) {
      var status = xhr.status;
      if ((status > 399 && status < 600) || status == 400) {
        throw 'File read error on ' + xhr.responseURL;
      }
      else
        output = xhr.responseText;
    }
  }
  xhr.send(null);
  return output;
}

From https://github.com/jspm/nodelibs-fs/blob/master/fs.js 来自https://github.com/jspm/nodelibs-fs/blob/master/fs.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM