ng-annotate-loader Typescript processing order
See original GitHub issueDescribe the bug I’m upgrading an AngularJS 1.6 project with ngUpgrade to run both ng+ and AngularJS code in the same project.
The AngularJS code requires ng-annotate-loader for DI annotations.
ng-annotate-loader should run AFTER the Angular CLI webpack rules have parsed TypeScript, as ng-annotate-loader cannot parse TypeScript.
angular.json
"customWebpackConfig": {
"path": "src/extra-webpack.config.ts"
},
webpack.config.ts
const path = require('path');
module.exports = {
// @todo ng-annotate-loader is trying to annotate TypeScript before it has been processed by ts-loader.
module: {
rules: [
{
// Do we target TypeScript that has been processed by ts-loader?
test: /\.ts?$/,
// Or do we somehow target JS after ts-loader has finished processing?
// test: /\.js?$/,
// Only parse the AngularJS scripts (that require DI annotations).
include: [
path.resolve(__dirname, 'legacy'),
],
use: [
{
loader: 'ng-annotate-loader',
options: {
ngAnnotate: 'ng-annotate-patched',
}
},
]
},
]
}
};
Error:
ERROR in ./src/legacy/shared/components/app-version/app-version.component.ts
Module build failed (from ./node_modules/ng-annotate-loader/loader.js):
NonErrorEmittedError: (Emitted value instead of an instance of Error) error: couldn't process source due to parse error,Unexpected token (5:25)
at runLoaders (/Users/mastone/Work/Everwealth.WebAppMigration/node_modules/webpack/lib/NormalModule.js:283:13)
at /Users/mastone/Work/Everwealth.WebAppMigration/node_modules/loader-runner/lib/LoaderRunner.js:364:11
at /Users/mastone/Work/Everwealth.WebAppMigration/node_modules/loader-runner/lib/LoaderRunner.js:230:18
at Object.context.callback (/Users/mastone/Work/Everwealth.WebAppMigration/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at Object.module.exports (/Users/mastone/Work/Everwealth.WebAppMigration/node_modules/ng-annotate-loader/loader.js:87:10)
To Reproduce Steps to reproduce the behavior:
- Go to ‘…’
- Click on ‘…’
- Scroll down to ‘…’
- See error
OR (preferred way)
a link to a repository with minimal reproduction
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Builder:
- The name of the builder
- The version of the builder
Libraries
"@angular-builders/custom-webpack": "^7.1.1",
"@angular-builders/dev-server": "^7.1.1",
"@angular-devkit/build-angular": "^0.11.4",
"ng-annotate-loader": "^0.6.1",
"ng-annotate-patched": "^1.7.0",
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
ng-annotate-loader Typescript processing order #186 - GitHub
Describe the bug I'm upgrading an AngularJS 1.6 project with ngUpgrade to run both ng+ and AngularJS code in the same project.
Read more >How to use ng-annotate with hybrid app based on angular-cli
So, the way to do this is by using webpack-merge and custom-webpack. This is the configuration to run ng-annotate with Typescript files :...
Read more >ng-annotate-loader - npm
Webpack loader that runs ng-annotate on your bundles. Latest version: 0.7.0, last published: 3 years ago. Start using ng-annotate-loader in ...
Read more >Using ng-annotate for min-safe AngularJS - Egghead.io
This is a problem for AngualrJS, which uses parameter names to provide injected dependencies. You could use the array notation manually, but no ......
Read more >Ng-annotate NPM - npm.io
ng -annotate supports ES5 as input so run it with the output from Babel, Traceur, TypeScript (tsc) and the likes. Use "ngInject" on...
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
@meltedspark Both options have solved my issue. I was trying to merge
loaders
as outlined in the documentation:Thank you for your help!
Hey! My extended.webpack.config file is something like:
Errors I’m getting are something like:
Should ng-annotate run before Angular’s webpack-loader ?