ng-cli-pug-loader icon indicating copy to clipboard operation
ng-cli-pug-loader copied to clipboard

Angular 11 brand-new project issues

Open TheNemus opened this issue 5 years ago • 12 comments

I just created a brand-new angular project with

ng new my-app

The app runs without problems. Then I add the schematics:

ng add ng-cli-pug-loader

this is what I got back:

Installing packages for tooling via npm.
Installed packages for tooling via npm.
CLI's Webpack config was not found. Try running `npm install` before running this tool.

I then run npm i as suggested, then the schematics:

Skipping installation: Package already installed
CLI's Webpack config was not found. Try running `npm install` before running this tool.

If I try to run the app with pug inside, I get some errors in console:

Error: Module parse failed: Unexpected token (10:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
| style.
>   :host {
|   font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|   font-size: 14px;

While the app works fine in browser. What does those issues mean? How can I avoid them?

TheNemus avatar Nov 17 '20 14:11 TheNemus

Please check this error #37, maybe this can help you.

ChickenRunVN avatar Nov 17 '20 15:11 ChickenRunVN

new angular-devkit not include common.js we need change config in ng-add-pug-loader,js

lxandrexl avatar Nov 18 '20 13:11 lxandrexl

new angular-devkit not include common.js we need change config in ng-add-pug-loader,js

@lxandrexl The common.js file only move location, you can check #37 for more detail. Here is the new location:

const commonCliConfig = 'node_modules/@angular-devkit/build-angular/src/webpack/configs/common.js';

const typescriptCliConfig = 'node_modules/@angular-devkit/build-angular/src/webpack/configs/typescript.js';

ChickenRunVN avatar Nov 18 '20 13:11 ChickenRunVN

new angular-devkit not include common.js we need change config in ng-add-pug-loader,js

@lxandrexl The common.js file only move location, you can check #37 for more detail. Here is the new location:

const commonCliConfig = 'node_modules/@angular-devkit/build-angular/src/webpack/configs/common.js';

const typescriptCliConfig = 'node_modules/@angular-devkit/build-angular/src/webpack/configs/typescript.js';

after trying to install the schematics I've got no ng-add-pug-loader.js in my project, maybe because the schematics itself failed

TheNemus avatar Nov 23 '20 12:11 TheNemus

after trying to install the schematics I've got no ng-add-pug-loader.js in my project, maybe because the schematics itself failed

Hi @TheNemus , could you please commit your repository or guide me try to reproduce it step-by-step so I can take a look at it?

ChickenRunVN avatar Nov 23 '20 14:11 ChickenRunVN

after trying to install the schematics I've got no ng-add-pug-loader.js in my project, maybe because the schematics itself failed

Hi @TheNemus , could you please commit your repository or guide me try to reproduce it step-by-step so I can take a look at it?

sure. Upgrade your ng CLI to 11.0.x, then:

ng new my-app ng add ng-cli-pug-loader

that's all

TheNemus avatar Nov 23 '20 15:11 TheNemus

sure. Upgrade your ng CLI to 11.0.x, then:

ng new my-app ng add ng-cli-pug-loader

that's all

Well, I have tried and found the problem with the detail as below:

const TARGET_COMMON_CONFIG_PATH = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js';
const TARGET_TYPESCRIPT_CONFIG_PATH = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/typescript.js';
const NG_ADD_PUG_LOADER_SCRIPT_NAME = 'ng-add-pug-loader.js';

....

if (!commonConfigFile || !typescriptConfigFile)
  return throwError(new Error(`CLI's Webpack config was not found. Try running \`npm install\` before running this tool.`));

which will cause the error because the path for common.js and typescript.js has been changed, and that means you will not able to create a new project using ng add ng-cli-pug-loader command. The Author @danguilherme of this project hadn't been updated for a while so I think we won't have a new version to fix this soon.

  • So, here is the way to work around and make your new project work with Angular 11:
  1. Init new project with ng new <your app name> command.
  2. Navigate to your new project folder.
  3. Instead of using ng add ng-cli-pug-loader, you will have to install project dependency and script for pug manually.
  • First, install dependency with this command npm install apply-loader@~2.0.0 pug-loader@~2.4.0 pug@~2.0.3 --save-dev
  • Create new script file ng-add-pug-loader.js in your project. You can find the initial for the file content here.
  • Open the file, find and replace the content for some variables as below:
const commonCliConfig = 'node_modules/@angular-devkit/build-angular/src/webpack/configs/common.js';
const pugRules = '{test:/\\.(pug|jade)$/,exclude:/\\.(include|partial)\\.(pug|jade)$/,use:[{loader:"apply-loader" },{loader:"pug-loader"}]},{test:/\\.(include|partial)\\.(pug|jade)$/,loader:"pug-loader"},';
const typescriptCliConfig = 'node_modules/@angular-devkit/build-angular/src/webpack/configs/typescript.js';
  • Open your package.json, add "postinstall": "node ./ng-add-pug-loader.js" in the scripts section.
  1. Run npm i command.

I have created a sample for you to check if needed, you can find it here. Hope that will help to solve your problem. Happy coding!

ChickenRunVN avatar Nov 23 '20 16:11 ChickenRunVN

What happens next?

David-van-der-Sluijs avatar Jan 29 '21 18:01 David-van-der-Sluijs

Sooo ... did we lose this project ?

mp3por avatar Jun 16 '21 13:06 mp3por

I can't believe this project has been abandoned. Any other way of using .pug file with Angular ?

guilmarc avatar Nov 10 '21 11:11 guilmarc

@guilmarc, Angular Pug Builders - it could be used for Angular >=v12. It uses @angular-devkit/build-angular native builders as a dependency and extends them with webpack pug rules.

To use it with the current Angular version just run:

  ng add ngx-pug-builders

or for Angular 12:

  ng add ngx-pug-builders@12

See details here.

lekhmanrus avatar Dec 07 '21 17:12 lekhmanrus

@guilmarc, Angular Pug Builders - it could be used for Angular >=v12. It uses @angular-devkit/build-angular native builders as a dependency and extends them with webpack pug rules.

To use it with the current Angular version just run:

  ng add ngx-pug-builders

or for Angular 12:

  ng add ngx-pug-builders@12

See details here.

Man, thank you so much, my application it's working now. I spent days trying to use pug and you helped me!!

vitoneto avatar Aug 29 '22 12:08 vitoneto

@lekhmanrus Looks like that project is abandoned now too? I see that it has not been released in a while an no 17 support?

jrgleason avatar Nov 19 '23 17:11 jrgleason

NM now I see this so it sounds like it will be some time before 17 support

https://github.com/lekhmanrus/ngx-pug-builders/issues/10

jrgleason avatar Nov 19 '23 17:11 jrgleason

Hi @jrgleason, new version just released. Btw, see currently supported builders.

lekhmanrus avatar Nov 21 '23 19:11 lekhmanrus

Hey there @lekhmanrus, as this repo is not maintained I'll link to your project in the README if that's alright.

danguilherme avatar Nov 21 '23 22:11 danguilherme

Hi @danguilherme, sure, thanks. 🙂

lekhmanrus avatar Nov 21 '23 23:11 lekhmanrus

This project is no longer maintained. Check out ngx-pug-builders to add support to pug files to your Angular project.

danguilherme avatar Nov 22 '23 00:11 danguilherme