我无法添加解压缩

I cannot add unzip

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

而且我英语不好

对不起。

我想使用这个模块。

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')" ,我得到了错误。

Uncaught Error: No such module. (Possibly not yet loaded)

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

WARNING Compiled with 3 warnings 16:03:20

warning in ./node_modules/natives/index.js

Critical dependency: the request of a dependency is an expression

warning in ./node_modules/lazy-debug-legacy/src/functions.js

Critical dependency: the request of a dependency is an expression

warning in./node_modules/lazy-debug-legacy/src/functions.js

Critical dependency: the request of a dependency is an expression

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

我也用过这个模块

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

但如果我这样做了

var unzipper = require('unzipper');

我遇到了不同的错误。

polyfills.js?a0a3:32 Uncaught TypeError: Cannot read property 'match' of undefined

我的完整代码。

//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>

此库不适用于浏览器环境 - 它依赖于 Node.js 特定模块,这些模块在浏览器中不可用。

您不能在浏览器环境中使用 'fs' 或 'unzip'。它们旨在用于 Node.js 运行时。 Javascript 在网页中执行无权访问底层文件系统。 (有Filesystem API,但它只是一个虚拟文件系统,只有chrome支持它)

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

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

yarn add --save unzip 所以你的申请可以通过 package.json

解决

编辑

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