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.

Issue with webpack statically extracted dependencies

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior Throwing a warning that is turned into a hard error with static files build.

WARNING in ./~/ng2-translate/bundles/ng2-translate.js
Critical dependencies:
1:2208-2215 require function is used in a way in which dependencies cannot be statically extracted
1:2254-2261 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/ng2-translate/bundles/ng2-translate.js 1:2208-2215 1:2254-2261

Which leads to this output in the console with static files:

Uncaught TypeError: Cannot read property 'resolve' of undefined
Uncaught TypeError: Cannot read property 'forRoot' of undefined

Reproduction of the problem

git clone git@github.com:angular/angular2-seed.git
cd angular2-seed
npm install
npm install --save ng2-translate

In src/vendor.browser.ts

import 'ng2-translate';

In src/app/app.module.ts

import { TranslateModule } from 'ng2-translate'; // <<<<<<<<<<<<<<<<<<<< <  added

@NgModule({
  declarations: [AppComponent, About, RepoBrowser, RepoList, RepoDetail, Home],
  imports     : [
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule.forRoot(rootRouterConfig),
    TranslateModule.forRoot() // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <added
  ],
  providers   : [Github, {provide: LocationStrategy, useClass: HashLocationStrategy}],
  bootstrap   : [AppComponent]
})
export class AppModule {

}

Please tell us about your environment:

  • ng2-translate version: 3.1.0
  • Angular version: 2.0.0
  • Browser: [Chrome 53]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:36 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Redigast13commented, Oct 14, 2016

I had the same issue. Solution:

  1. Replace all import { … } from ‘ng2-translate’; to import { … } from ‘ng2-translate/ng2-translate’;
  2. Add babel loader for js files because node_modules/ng2-translate/ng2-translate.js file has ECMA 6 syntax.

Here is my webpack loader configuration:

{
    test: /\.js$/,
    include: /ng2-translate/,           
    loader: 'babel',
    query: {
        presets: ['es2015']
    }
}
4reactions
rlopez4commented, Oct 17, 2016

Thanks for the suggestion @Redigast13. I actually just re-used the typescript loader so I wouldn’t have to add babel. Here’s the loader configuration I added:

      {
        test: /\.js$/,
        include: /ng2-translate/,
        loader: 'awesome-typescript-loader'
      },
Read more comments on GitHub >

github_iconTop Results From Across the Web

require function is used in a way in which dependencies ...
From what I understand, this warning means the dependencies are not statically analyzable, and thus cannot be tree-shaken. Is this correct? Is ...
Read more >
"Critical dependency: require function is used in a way in ...
"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted" with Webpack and typescript.
Read more >
Incompatible with Webpack - Google Groups
I was trying to utilize Cesium in an application that utilizes Webpack and ran into numerous ... in which dependencies cannot be statically...
Read more >
[NODE-3389] No longer possible to bundle statically
Many projects use Webpack to build the server-side code. ... function is used in a way in which dependencies cannot be statically extracted....
Read more >
A Guide to Managing Webpack Dependencies - Toptal
The Webpack module bundler processes JavaScript code and all static assets, ... We can easily handle this issue with Webpack's resolve.alias option.
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