Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack Module not found: Error: Can't resolve 'fs' in 'node_modules/qrcode-svg/lib' #11

Open
jantimon opened this issue May 6, 2020 · 4 comments · May be fixed by #20
Open

Webpack Module not found: Error: Can't resolve 'fs' in 'node_modules/qrcode-svg/lib' #11

jantimon opened this issue May 6, 2020 · 4 comments · May be fixed by #20

Comments

@jantimon
Copy link

jantimon commented May 6, 2020

Can you please remove .save()?

qrcode-svg/lib/qrcode.js

Lines 405 to 420 in 47d56ec

/** Writes QR Code image to a file */
QRCode.prototype.save = function(file, callback) {
var data = this.svg();
if (typeof callback != "function") {
callback = function(error, result) { };
}
try {
//Package 'fs' is available in node.js but not in a web browser
var fs = require('fs');
fs.writeFile(file, data, callback);
}
catch (e) {
//Sorry, 'fs' is not available
callback(e);
}
};

Saving files to disk is very easy in node and the developer can decide wether they need to use sync or async:

fs.writeFileSync("qr.svg", new QRCode("abc").svg());
@ritingliudd01
Copy link

Met with the same issue.

@sonhle
Copy link

sonhle commented May 26, 2020

I'm trying this in an angular project and having the same warning.

@buzinas
Copy link

buzinas commented Jul 9, 2020

Projects that depend on fs, you can just add the code below to your webpack's configuration file:

module.exports = {
  // ...
  node: {
    fs: 'empty',
  },
  // ...
};

@denydias
Copy link

denydias commented Dec 23, 2020

With webpack 5/laravel-mix 6 this sould be:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants