alexcorvi / heic2any

Converting HEIF/HEIF image formats to PNG/GIF/JPEG in the browser
https://alexcorvi.github.io/heic2any/
MIT License
626 stars 82 forks source link

ERROR : Can't resolve 'fs' #1

Closed mlh-trungdq closed 4 years ago

mlh-trungdq commented 5 years ago

Thank you for the tool! I had an error adding the library to my component. "_ERROR in ./node_modules/heic2any/dist/index.js Module not found: Error: Can't resolve 'fs' in 'D:\projects\myproject\nodemodules\heic2any\dist'"

Can you suggest how to fix it?

alexcorvi commented 5 years ago

no fix, just a workaround, define fs, path and crypto as externals in your module bundler (i.e. webpack).

Here's an example on how to do it in webpack configuration file:

module.exports = {
        // ....
    externals: {
        fs: "fs",
        path: "path",
        crypto: "crypto"
    },
        // ....
}
mlh-trungdq commented 5 years ago

ThankYou. I love it!!

zacharytyhacz commented 4 years ago

For nuxtJS in a nuxt.config.js file, add this similar piece of text:

// nuxt.config.js

export default {

    ...

    build: {

        ...

        extend: function (config, {isDev, isClient}) {

            config.node = {

                fs: "empty"
            };
        }
    },

    ...
};
zzarcon commented 4 years ago

Hi there! Thanks for the lib :)

I just added the lib to my project and I'm facing this issue. IMO this issue should be fixed at the library level rather than on the consumer Webpack config, otherwise, every single user will have to trick their configs in order to make it work, and in some cases that is not as simple.

Perhaps adding the external into the Rollout config? Or find out a different way, what do you think?

believe2016 commented 4 years ago

本地项目连接的测试环境上传头像转换没问题,打包上测试后上传头像一上传整个页面就卡住崩了,也不报错,是什么原因呢