papnkukn/qrcode-svg

Can't resolve 'fs'

amcsi opened this issue · 10 comments

amcsi commented

When requiring this library for browser frontend use, I get this error.

Everything works otherwise, it's just this error showing in the console is annoying.

Same for me, using preact-cli

ktviz commented

Same here in a Vue project, and this error prevents compilation. Any insights are welcome.

same here using straight node

appears that by adding the following export into my webpack config that the library works:

node: {
    fs: 'empty'
},

Same here in Angular project, it prevents compilation too.

The issue has been with the function save which works fine in node.js environment. However, a web browser does not have an open access to the file system, thus resulting in an error (require('fs'))

Hope the issue has been resolved with the version 1.1.0. Invoking the save(...) in a web browser will kindly pass the error in a callback function.

The issue has been with the function save which works fine in node.js environment. However, a web browser does not have an open access to the file system, thus resulting in an error (require('fs'))

Hope the issue has been resolved with the version 1.1.0. Invoking the save(...) in a web browser will kindly pass the error in a callback function.

Hi, do you mean we cannot use this library with frontend code?
But it is working fine in this example https://codepen.io/bocko/pen/YLWNgj

Yes, the library works fine within the browser (frontend) - the algorithm is pure JavaScript after all.

Just to make it clear - only the save function is not available in the browser.

The problem is still there for angular projects. It does build but with a warning
/node_modules/qrcode-svg/lib/qrcode.js:413:13-26 - Warning: Module not found: Error: Can't resolve 'fs' in '...\node_modules\qrcode-svg\lib'

Why do we even need this save function that writes just the qrcode to a file?
Most of the time I just need the qrcode to insert it in a document, maybe save in a database, and send it to the printer.

For laravel-mix:

// webpack.mix.js

mix.webpackConfig({
    resolve: {
        fallback: {
            fs: false
        }
    }
});