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 be compiled with Babel 7

See original GitHub issue

Hello, I get the following error trying to import the aws-sdk module in my react app.

ERROR in ../node_modules/aws-sdk/lib/event_listeners.js
Module not found: Error: Can't resolve 'util' in 'myproject-root/node_modules/aws-sdk/lib'

The app is compiled using @babel/core@7.1.2 and babel-loader@8.0.4 which are the last version on babel cores and loader.

Tried the same thing in another project using @babel/core@6.6.5 and babel-loader@7.1.2 and all works just fine.

Any idea? Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
rfdccommented, Nov 13, 2018

@chrisradek ok, I just found the bug and the solution and it was just simple and crazy at the same time.

The problem is basically introduced by a resolve alias override in the webpack config.

resolve: {
    alias: {
        assets: `${this.srcPathAbsolute}/assets/`,        
        app: `${this.srcPathAbsolute}/app/`,
        styles: `${this.srcPathAbsolute}/styles/`,
        // util: `${this.srcPathAbsolute}/util/`
    },
    extensions: ['.js', '.jsx'],    
}

Above the relevant configuration file that causes the issue. As you can see in the commented line, there is a new alias for util redefined as the path of a util file contained in the project. The skeleton of the project is part of a template that uses this alias for convenience, but in this case causes problems since the util alias redefinition change the result of each require('util') or import util from 'util'. I tried to comment that line and the aws-sdk import works just fine (for real this time).

To summarise, it doesn’t looks like the problem is from the aws-sdk itself but from a quirk in the config.

P.S. I will rename the alias to myUtil or something similar to avoid conflicts, but maybe could be safer to rename the aws-sdk util file too to something less common?

it solved my problem too…thanks guys 💯

1reaction
srchasecommented, Oct 19, 2018

@simonemazzoni

Thanks for working with us on this issue. I’m going to close this out. Appreciate the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel 7 can't compile in node_modules · Issue #8672 - GitHub
v7 Regression Describe the regression I'm upgrade my webpack from babel6 to babel7, but i get a unexpected result when using babel7。
Read more >
Why is Babel 7 not compiling node_modules files?
New in Babel 7.x, Babel has as concept of a "root" directory, which defaults to the current working directory. For project-wide configuration, ...
Read more >
Upgrade to Babel 7
In Babel 6, values passed to Babel directly (not from a config file), were resolved relative to the files being compiled, which led...
Read more >
Babel vs. TypeScript: Choosing the right compiler for your ...
Should you use Babel? TypeScript? Both? See how the two JavaScript compilers compare through performance, custom transformations, and more.
Read more >
@babel/helper-compilation-targets - npm
Helper functions on Babel compilation targets. Latest version: 7.20.7, last published: 4 days ago.
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