16

I found this issues in the official, but it looks like they refused to answer. So I can only ask questions on SO. Here is my Error&Warning Log:

WARNING in ./~/aws-sdk/lib/util.js
Critical dependencies:
40:30-45 the request of a dependency is an expression
43:11-53 the request of a dependency is an expression
 @ ./~/aws-sdk/lib/util.js 40:30-45 43:11-53

WARNING in ./~/aws-sdk/lib ^\.\/.*$
Module not found: Error: Cannot resolve directory '.' in /Users/me/Documents/Sources/my-project/client/node_modules/aws-sdk/lib
 @ ./~/aws-sdk/lib ^\.\/.*$

WARNING in ./~/aws-sdk/lib/api_loader.js
Critical dependencies:
13:15-59 the request of a dependency is an expression
104:12-46 the request of a dependency is an expression
108:21-58 the request of a dependency is an expression
114:18-52 the request of a dependency is an expression
 @ ./~/aws-sdk/lib/api_loader.js 13:15-59 104:12-46 108:21-58 114:18-52

WARNING in ./~/aws-sdk/lib/region_config.json
Module parse failed: /Users/me/Documents/Sources/my-project/client/node_modules/aws-sdk/lib/region_config.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "rules": {
|     "*/*": {
|       "endpoint": "{service}.{region}.amazonaws.com"
 @ ./~/aws-sdk/lib ^\.\/.*$

ERROR in ./~/aws-sdk/lib/api_loader.js
Module not found: Error: Cannot resolve module 'fs' in /Users/me/Documents/Sources/my-project/client/node_modules/aws-sdk/lib
 @ ./~/aws-sdk/lib/api_loader.js 1:9-22

ERROR in ./~/aws-sdk/lib/services.js
Module not found: Error: Cannot resolve module 'fs' in /Users/me/Documents/Sources/my-project/client/node_modules/aws-sdk/lib
 @ ./~/aws-sdk/lib/services.js 1:9-22

There are three types:

  1. Cannot resolve module 'fs'

I only need to install fs can solve this.

  1. need an appropriate loader

Well, this will need to install json-loader, and set it in webpack.config.js, but also can solve.

  1. Critical dependencies
  2. Module not found: Error: Cannot resolve directory '.'

I webpack newbie.So, i don't know how to solve this. Will someone help me? thanks.

UPDATE:

  1. Module not found: Error: Cannot resolve directory '.'

that is my fault, config file's extensions missing a .

6 Answers 6

6

I found this blog post that fixed it for me.

Essentially you need to import the built version of the library.

All credit goes to the author. Here is the code:

require('aws-sdk/dist/aws-sdk');
var AWS = window.AWS;

ES6 version:

import 'aws-sdk/dist/aws-sdk';
const AWS = window.AWS;
1
  • I encountered this problem installing aws-amplify, which depends on aws-sdk, so the issue still seems to exist. doesn't seem great to have to edit the aws-amplify code to have to get it working though Jul 26, 2018 at 9:03
3

config:

module: {
  noParse: [
   /aws/
  ]
}

usage:

window.AWS to the reference of the global AWS object.

2

Using the noParse method should work if you are creating a node package, as this is setting webpack to not apply any parsing/loaders. This did not work for me when creating a umd formatted output file/library.

To create a umd formatted library I had to use loaders to Browserify aws-sdk and handle json files.

Install the loaders:

npm install json-loader --save-dev

npm install transform-loader brfs --save-dev

Webpack Config:

module: {
  loaders: [
    { test: /aws-sdk/, loaders: ["transform?brfs"]},
    { test: /\.json$/, loaders: ['json']},
  ]
},
output: {
  library: 'LibraryName',
  libraryTarget: 'umd'
},
resolve: {
  extensions: ['', '.js']
}

Replace LibraryName with you own namespacing. Currently the library would be used through a constructor as follows:

var libObj = new LibraryName();
1
  • Error: configuration.module has an unknown property 'loaders'
    – lzl124631x
    Jun 27, 2018 at 17:35
2

AWS SDK added support to webpack starting from version 2.6.1, please see Using webpack and the AWS SDK for JavaScript to Create and Bundle an Application – Part 1 blog post describing how to require aws-sdk into webpack bundle.

1
  • This is the way to do it now!
    – Tim
    Dec 20, 2016 at 8:49
0

use npm install json-loader --save-dev add the following code to webpack.config.js

  module: {
loaders: [{
  test: /\.js$/,
  loaders: ['babel'],

  exclude: /node_modules/,
},
{
      test: /.json$/,
      loaders: ['json']
    }]

}

Just import * as AWS from 'aws-sdk'

Notice that we specified a loader to tell webpack how to handle importing JSON files, in this case by using the json-loader we installed earlier. By default, webpack only supports JavaScript, but uses loaders to add support for importing other file types as well. The AWS SDK makes heavy use of JSON files, so without this extra configuration, webpack will throw an error when generating the bundle.

-3

Update(2015-10-20):

aws-sdk fix this. i can use it from npm.

thanks, aws-sdk team.

1
  • 1
    Really? It is still broken for me.
    – Nick Cox
    Jul 21, 2016 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.