【问题标题】:I cannot add unzip我无法添加解压缩
【发布时间】:2018-10-12 06:59:19
【问题描述】:

我是日本初学者的网络开发者。

而且我英语不好。

对不起。

我想使用这个模块。

https://www.npmjs.com/package/unzip

所以我做了yarn add unzipyarn add fsyarn add module v8yarn add request@2.79.0

我做到了

var fs = require('fs');
var unzip = require('unzip');

但是因为 "require('unzip')" ,我得到了错误。

未捕获的错误:没有这样的模块。 (可能尚未加载)

我在构建时遇到了这个错误。

WARNING 编译时有 3 个警告 16:03:20

./node_modules/natives/index.js 中的警告

关键依赖:依赖的请求是一个表达式

./node_modules/lazy-debug-legacy/src/functions.js 中的警告

关键依赖:依赖的请求是一个表达式

警告在./node_modules/lazy-debug-legacy/src/functions.js

关键依赖:依赖的请求是一个表达式

有人告诉我解决这个问题的方法吗? 我不能使用解压缩模块。

我也用过这个模块。

https://www.npmjs.com/package/unzipper

如果我这样做了

var unzipper = require('unzipper');

我得到了不同的错误。

polyfills.js?a0​​a3:32 Uncaught TypeError: Cannot read property 'match' 未定义的

我的完整代码。

//converter.ts
var fs = require('fs');
var unzipper = require('unzipper');

export default function converter(file) {

    console.log(file)

    //     fs.createReadStream(file)
    //         .pipe(unzipper.Extract({ path: './tmp/' }));

}

//convert.vue
<template>

  <div class="convert">

  </div>

</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";

import converter from "./converter"

@Component({
  components: {}
})
export default class Convert extends Vue {

    mounted(){
        converter("./resources/text.zip")
    }

}
</script>

<style lang="scss">
</style>

【问题讨论】:

  • 你的英文还可以,但如果你觉得你更喜欢用日文写作,你可以查看ja.stackoverflow.com
  • 谢谢。但是这里有更好的开发者(T____T)
  • node --version 说什么?你是用yarn add unzip还是npm i -S unzip添加的?
  • node -v 是“v9.5.0”,我添加了纱线!!!我正在使用 vue-cli3.0。
  • 您正在尝试在浏览器 (Vue.js) 中使用该库?

标签: javascript typescript yarnpkg


【解决方案1】:

您不能在浏览器环境中使用“fs”或“解压缩”。它们旨在用于 Node.js 运行时。在网页中执行的 Javascript 无法访问底层文件系统。 (有Filesystem API,不过只是虚拟文件系统,只有chrome支持)

如果你想在跨浏览器环境中使用模拟文件系统,你可以看看https://www.npmjs.com/package/fs-web

【讨论】:

    【解决方案2】:

    这个库并不打算在浏览器环境中使用 - 它依赖于 Node.js 特定的模块,这些模块在浏览器中不可用。

    【讨论】:

    • 无法在浏览器中使用。你需要一个 Node.js 后端服务器——你可以在那里使用它。
    【解决方案3】:

    您必须使用--save--save-dev 标志安装unzip

    yarn add --save unzip 所以您的应用程序可以通过 package.json

    解决它

    编辑

    fs 之所以有效,是因为它是内置的 Node.Js。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-02
      相关资源
      最近更新 更多