Issue with webpack statically extracted dependencies
See original GitHub issueI’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:
- Created 7 years ago
- Reactions:1
- Comments:36 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue. Solution:
Here is my webpack loader configuration:
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: