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

Error: Can't resolve 'fs' #126

Closed
hoIIer opened this issue Sep 15, 2018 · 5 comments
Closed

Error: Can't resolve 'fs' #126

hoIIer opened this issue Sep 15, 2018 · 5 comments

Comments

@hoIIer
Copy link

hoIIer commented Sep 15, 2018

Hello, I installed ember-auto-import and getting errors with a package https://github.com/aws/aws-iot-device-sdk-js

Any ideas?

Possibly related: webpack-contrib/css-loader#447

Module not found: Error: Can't resolve 'fs' in '/Users/eric/Projects/foo/build/client-web/node_modules/aws-iot-device-sdk/common/lib'
 @ ./node_modules/aws-iot-device-sdk/common/lib/tls-reader.js 17:14-27
 @ ./node_modules/aws-iot-device-sdk/device/index.js
 @ ./node_modules/aws-iot-device-sdk/index.js
 @ ./tmp/ember_auto_import_webpack-staging_dir-SI7UQUPH.tmp/app.js

ERROR in ./node_modules/aws-iot-device-sdk/device/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/eric/Projects/foo/build/client-web/node_modules/aws-iot-device-sdk/device'
 @ ./node_modules/aws-iot-device-sdk/device/index.js 29:9-22
 @ ./node_modules/aws-iot-device-sdk/index.js
 @ ./tmp/ember_auto_import_webpack-staging_dir-SI7UQUPH.tmp/app.js

ERROR in ./node_modules/aws-iot-device-sdk/device/lib/tls.js
Module not found: Error: Can't resolve 'tls' in '/Users/eric/Projects/foo/build/client-web/node_modules/aws-iot-device-sdk/device/lib'
 @ ./node_modules/aws-iot-device-sdk/device/lib/tls.js 17:10-24
 @ ./node_modules/aws-iot-device-sdk/device/index.js
 @ ./node_modules/aws-iot-device-sdk/index.js
 @ ./tmp/ember_auto_import_webpack-staging_dir-SI7UQUPH.tmp/app.jsBuild Error (Bundler)

webpack returned errors to ember-auto-import```
@hoIIer hoIIer changed the title Multiple errors with aws-iot-device-sdk Error: Can't resolve 'fs' Sep 15, 2018
@ef4
Copy link
Collaborator

ef4 commented Sep 15, 2018

Try following their Using SDK with Webpack instructions. ember-auto-import is implemented on top of webpack, deliberately because so many other libraries out there already have documented support for how to make it work.

Alternatively, if the dependency on fs is the only issue, you might be able to work around it like this:

const app = new EmberApp({
    autoImport: {
      webpack: {
        node: {
          fs: 'empty'
        }
      }
    }
})

That assumes the library isn't really going to try to use fs, which obviously can't work in the browser.

@hoIIer
Copy link
Author

hoIIer commented Sep 15, 2018

@ef4 thanks Edward that worked like a charm!

    autoImport: {
      webpack: {
        node: {
          fs: 'empty',
          tls: 'empty',
        },
      },
    },

@hoIIer hoIIer closed this as completed Sep 15, 2018
@hilljh82
Copy link

@ef4 Do you have any suggestions for handling the same issue when using it in an ember add-on? I can add the recommended code to ember-cli-build.js and it works, but ember-cli-build.js is not included when the add-on is installed. I personally do not want to require the user to add the code above to their ember application.

@hilljh82
Copy link

hilljh82 commented Oct 18, 2018

@ef4 To answer my own question about, i just added the following to the index file for the add-on:

const merge = require ('lodash.merge');

module.exports = {
  // ...

  included (app) {
    this._super (...arguments);

    merge (app.options, {
      autoImport: {
        webpack: {
          node: {
            fs: 'empty'
          }
        }
      }
    });
  },
};

I do not know if this is the right way since I am changing the application options on-the-fly, but it works. If you have a better suggestion, then please let me know.

Update: This approach worked with the dummy test application, but did not work when using the add-on in an ember application.

@yaxinr
Copy link

yaxinr commented Jul 30, 2021

in webpack 5 must be

autoImport: {
      webpack: {
        resolve: {
          fallback: {
            fs: false,
            path: 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

No branches or pull requests

4 participants