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.

@ngtools/webpack doesn't chain loaders correctly

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.2.6 (e) node: 8.2.1 os: win32 x64 @angular/(all of them): 4.3.3 npm: 5.3.0 node: 8.2.1

Repro steps.

  1. ng new bugdemo
  2. cd bugdemo
  3. ng eject
  4. Create a very basic Webpack loader called dummy-loader.js: module.exports = function dummyLoader(source) { return source.replace("title = 'app'", "title = 'FOOBAR app'"); }
  5. Edit webpack.config.js, change: "loader": "@ngtools/webpack" to: "loader": ["@ngtools/webpack","./dummy-loader"]
  6. npm start
  7. Browse to http://localhost:4200/

The log given by the failure.

Actual output: Welcome to app!

Desired functionality.

Expected output: Welcome to FOOBAR app!

Mention any other details that might be useful.

The default project created by ng new generates app.component.html containing this: Welcome to {{title}}! and corresponding app.component.ts containing this: title = 'app'; The dummy-loader.js simply rewrites it to this: title = 'FOOBAR app';

If we edit webpack.config.js, remove: "loader": ["@ngtools/webpack","./dummy-loader"] and replace with: "loader": ["awesome-typescript-loader", "angular2-template-loader", "./dummy-loader"] then install the extra modules npm i awesome-typescript-loader angular2-template-loader then we get the correct output. So this is definitely a bug in @ngtools/webpack

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
zolaktcommented, Dec 14, 2017

I’m having this same issues. Does anyone have any advice on how to resolve it. The example is nearly identical to the posted one. I created a simple dummy loader that just replaces text.

I’m trying to replace a templateUrl in a component: templateUrl: './theme-##THEME##.html'

And the dummy loader:

module.exports = function dummyLoader(source) {
    return source.replace("##THEME##", "default");
}

I get this error (full path instead of …)

Module not found: Error: Can’t resolve ‘./…/$$_gendir/ClientApp/app/app.module.browser.ngfactory’ ERROR in Entry module not found: Error: Can’t resolve ‘…/blog/theme-##THEME##.html’

This happens only with production builds and AOT. This is the loader chain: ['@ngtools/webpack', 'angular-router-loader?aot=true', './dummy-loader']

It works with the develop chain, without AOT and ngtools: ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular-router-loader', './dummy-loader']

The component in question is inside a lazy loaded module, if it makes any difference. Tried lazy loading with sync options, didn’t change anything.

I have tried with a bunch of string/path/regex replace loaders instead of the dummy one. None yielded results.

I have also tried using the DefinePlugin instead of preprocessing and replacing strings. In that case, the global variable is not picked up in Component definitions. It resolves to undefined. But again, it works without AOT.

Any help is appreciated, I’m totally stuck on this. Currently I have to drop the whole theme system just to build for production.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 9, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngtools\webpack AOT doesn't work OR freezes at 95% emitting
But I guess the trick is for AoT, is to just make sure that you have a loader for EVERY file type that...
Read more >
webpack/webpack - Gitter
Hello everyone. I am ssh'ing into a secure zone for web development and recently upgraded to the latest version of angular and angular/cli....
Read more >
Switching from angular2-template-loader to @ngtools/webpack
Possible solution 1. You probably have bad import paths that webpack/node doesn't care about but the compiler does. · Possible solution 2.
Read more >
Known issues with PaperCut MF, NG, Hive, Pocket and ...
If a PaperCut Print Deploy server's Client Authentication method is set to AUTO or TRUST then PaperCut Mobility Print queues will fail to...
Read more >
vicads5-liveview - npm Package Health Analysis | Snyk
The npm package vicads5-liveview receives a total of 1 downloads a week. ... looking to learn about Webpack and ES6 Build Tools check...
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