Instascan: ES6 导入失败

创建于 2017-07-20  ·  5评论  ·  资料来源: schmich/instascan

我正在尝试通过 ES6 导入语句import InstaScan from 'instascan'导入库,这会引发以下错误:

ERROR in ./node_modules/instascan/src/zxing.js
Module not found: Error: Can't resolve 'fs' in 'C:\projects\my_project\node_modules\instascan\src'
 @ ./node_modules/instascan/src/zxing.js 4:725-738 4:313578-313591
 @ ./node_modules/instascan/src/scanner.js
 @ ./node_modules/instascan/index.js
 @ ./src/components/qrcode-scanner.component.js
 @ ./stories/qrcode-scanner.component.story.js
 @ ./stories/index.js
 @ ./.storybook/config.js

是不是我的 npm 设置又搞砸了,还是这个库不打算那样使用?
可能这只是 webpack 把事情搞砸了...

要使用 create-react-scripts 之一重现创建一个简单的基于反应的应用程序,请启动开发服务器并尝试从那里导入和/或要求它。

Windows 10 1607 内部版本 14393.1480
净下午 5.03
npm 模块fs全局和本地安装在项目文件夹中。

最有用的评论

将此添加到您的 webpack 配置中:

module.exports = {
  node: {
    fs: "empty"
  },
  entry: {
    app: [
      './src/main.js'
    ]
  },
...

就像在https://github.com/pugjs/pug-loader/issues/8#issuecomment -55568520

所有5条评论

我在反应中也遇到了这个问题。 我设法在instascan/src/zxing.js使用 find/replace 让它工作。 找到下面的 2 个短语并将它们替换为空字符串。

var fs=require("fs");
var nodeFS=require("fs");

老实说,我对 zxing.js 不是很熟悉,所以我不知道为什么会这样。

不知道为什么 webbrowser 目标库应该使用“fs”,但你绝对正确地认为这是问题所在!
非常感谢你!
为此进行 PR 合适还是@schmich 会考虑到这一点?

不幸的是,这个库破坏了我的 webpack 构建过程(与上面的问题相同)。 @rshepp的 hack 有效,但在一个项目中与多人合作时非常不切实际。

@axed你能做个公关吗? 那很好啊 :)

将此添加到您的 webpack 配置中:

module.exports = {
  node: {
    fs: "empty"
  },
  entry: {
    app: [
      './src/main.js'
    ]
  },
...

就像在https://github.com/pugjs/pug-loader/issues/8#issuecomment -55568520

将此添加到您的 webpack 配置中:

module.exports = {
  node: {
    fs: "empty"
  },
  entry: {
    app: [
      './src/main.js'
    ]
  },
...

就像在pugjs/pug-loader#8 中一样(评论)

alhamdulillah 比萨 :)

此页面是否有帮助?
0 / 5 - 0 等级