question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot build project with webpack v4

See original GitHub issue

Bug report

Cannot build a webpack project with the latest SDK installed, @aws-sdk/lib-storage@3.17.0. I get the following error: Module not found: Error: Can't resolve 'fs' in ...

Setup

Below is the minimal setup for reproducing this problem.

$ tree
.
├── package-lock.json
├── package.json
└── src
    └── index.js

1 directory, 3 files

Contents of package.json:

{
  "name": "ttt",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "webpack --mode development"
  },
  "devDependencies": {
    "webpack": "^4.46.0",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.2"
  },
  "dependencies": {
    "@aws-sdk/client-s3": "^3.17.0",
    "@aws-sdk/lib-storage": "^3.17.0"
  }
}

Contents of src/index.js:

import { S3Client } from '@aws-sdk/client-s3';
import { Upload } from '@aws-sdk/lib-storage';

console.log('+=+ S3Client', S3Client);
console.log('+=+ Upload', Upload);

What is the current behavior?

I get the following error:


ERROR in ./node_modules/@aws-sdk/lib-storage/dist/es/runtimeConfig.js
Module not found: Error: Can't resolve 'fs' in '/Users/korya/dev/ttt/node_modules/@aws-sdk/lib-storage/dist/es'
 @ ./node_modules/@aws-sdk/lib-storage/dist/es/runtimeConfig.js 3:0-31 7:106-115
 @ ./node_modules/@aws-sdk/lib-storage/dist/es/bytelength.js
 @ ./node_modules/@aws-sdk/lib-storage/dist/es/Upload.js
 @ ./node_modules/@aws-sdk/lib-storage/dist/es/index.js
 @ ./src/index.js

If the current behavior is a bug, please provide the steps to reproduce.

  1. Create the project
  2. Install deps: npm install
  3. Try to build it using npm run build (or just by running npx webpack)

What is the expected behavior?

The project should be successfully built and Upload imported @aws-sdk/lib-storage should be configured to work in browser’s environment (as expected).

Other relevant information: webpack version: 4.46.0 Node.js version: 15.14.0 npm version: 7.12.1 Operating System: MacOS Catalina Additional tools:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
koryacommented, Jun 5, 2021

Thanks again!

Just an update. The following config worked for webpack@4.46.0:

const path = require('path');

module.exports = {
  entry: './src/index.js',

  module: {
    rules: [
      {
        test: /@aws-sdk\/lib-storage\//,
        resolve: {
          alias: {
            './runtimeConfig': './runtimeConfig.browser',
          },
        },
      },
    ],
  },
};
0reactions
alexander-akaitcommented, Jun 5, 2021

Great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to build project using webpack and babel
SyntaxError: Cannot use import statement outside a module at Module._compile (internal/modules/cjs/loader.js:891:18) at Object.
Read more >
To v5 from v4 - webpack
This guide aims to help you migrating to webpack 5 when using webpack directly. If you are using a higher level tool to...
Read more >
Configuration - webpack
Out of the box, webpack won't require you to use a configuration file. However, it will assume the entry point of your project...
Read more >
Development - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Output Management - webpack
html file manually. However, a few plugins exist that will make this process much easier to manage. Preparation. First, let's adjust our project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found