Primeng with jhipster - jhipster

I have jhipster 6.6.0 version and I want to use primeng in my application generated with jhipster. After executing the command:
yo jhipster-primeng
eveything is ok but then I run:
npm install
and I get this error:
npm ERR! code ETARGET
npm ERR! notarget No matching version found for #angular/cdk#^8.2.14.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'jhipster-ui-libs'
npm ERR! notarget
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\48696\AppData\Roaming\npm-cache\_logs\2020-02-04T16_19_42_448Z-debug.log
What should I do to avoid this error?

The installation of primeng seems to always be a bit tricky, no matter the version. The instructions in this answer have been tested with JHipster 6.6.0.
1. Install PrimeNG
You must install a version of PrimeNG that is compatible with whatever version of angular JHipster is using. In this case JHipster 6.6.0 uses angular 8 so I installed version 8.1.1 of PrimeNG (the latest version 8 available).
You can use the following command if you use npm:
npm i primeng#8.1.1 primeicons #angular/animations
Or the following command if you use yarn:
yarn add primeng#8.1.1 primeicons #angular/animations
Remember that, in the future, you might be required to specify a compatible version of #angular/animations too.
2. Import the required PrimeNG modules
Now you must import the required modules, in my case just to test things I wanted to add a PrimeNG button so I imported the ButtonModule.
Open the [your-entity].module.ts file (or home.module.ts) and add the following lines:
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { ButtonModule } from 'primeng/button';
...
#NgModule({
imports: [..., BrowserAnimationsModule, ButtonModule],
...
})
In this second step it is very important to never import modules from primeng/primeng. You must use the specific module sub-folder like I did from 'primeng/button'.
3. Import the required css files
Open your vendor.scss file (or vendor.css if you do not use SCSS) and add the following:
...
// Import PrimeNG source files
#import '~primeng/resources/primeng.min.css';
#import '~primeng/resources/themes/nova-light/theme.css';
#import '~primeicons/primeicons.css';
...
At this point you should be able to add a p-button to your *.component.html file and it should be rendered without errors. Open two consoles and run .\mvnw and npm start respectively, as usual.
4. Add any extra dependency you need (Optional)
Very common example: you need to use ChartJS, you will have to add the dependency accordingly e.g.: npm i chart.js. Then add the import to your *.module.ts file:
import { ChartModule } from 'primeng/chart';
...
#NgModule({
imports: [..., ChartModule],
...
})
And finally add the bundle to your vendor.ts like this:
import 'chart.js/dist/Chart.bundle';
And now you should be able to add a chart like explained in the official primeng documentation.
I've published a repo in my github with the very minimum configuration required to start using PrimeNG in your JHipster 6.6.0 installation. You can find it here.
Changes, fixes and suggestions are welcome. I did this in a bit of a rush, my apologies.

Related

ERROR: npm ERR! code EOVERRIDE npm ERR! Override for axios#^1.2.0 conflicts with direct dependency

I have built an Azure chatbot that works fine in Bot Emulator locally but fails when I upload it to Azure. I get the following error:
npm ERR! code EOVERRIDE
npm ERR! Override for axios#^1.2.0 conflicts with direct dependency
I'm not entirely sure what this means. Does anyone know how to get around this?
I have tried to update the Axios package in both package-lock and package json files and nothing has worked
This error is due to the impact of packages in npm library related to axios package. We need to override the package manually using the below code block.
npm install axios-method-override
import axiosMethodOverride from 'axios-method-override';
axiosMethodOverride(axios);
const instance = axios.create();
axiosMethodOverride(instance);
we need to use override patch of HTTP, PUT, DELETE in this implementation.

How to check the version of custom npm modules?

I create a TypeScript Playground with custom npm modules in Plugins panel right side. But there is no version information for these npm modules. Where can I find the version information? Can I add a custom npm module with a specific version?

Cannot Import Material UI In React

I have installed #material-ui/icons using npm but anytime i run an import for
PS: I have Installed #material-ui/icons
import AccountCircleIcon from '#material-ui/icons/AccountCircle';
I get the following error
Failed to compile.
./node_modules/#material-ui/icons/utils/createSvgIcon.js
Module not found: Can't resolve '#material-ui/core/SvgIcon' in '/home/freduah/react-amazon-clone/node_modules/#material-ui/icons/utils'
Do you have Material Icons?
// with npm
npm install #material-ui/icons
// with yarn
yarn add #material-ui/icons
Check following page.
https://material-ui.com/components/icons/
As far I know you should have installed Material-UI itself. Because icons using SvgIcon components from the core package.
https://material-ui.com/components/material-icons/:
converted to SvgIcon components.
How to install the core package:
https://material-ui.com/getting-started/installation/
// with npm
npm install #material-ui/core
// with yarn
yarn add #material-ui/core`

npm install fails because package is missing in registry

I have an issue with a project where we are using node and brunch. The issue is current specific to brunch, but could occur for any module would be my guess.
The easiest way to currently reproduce this, is to do the following in a new folder:
npm init
npm install --save-dev brunch
The issue here is that brunch depends on loggy, which in turn depends on ansi-color, which no longer has an entry in the npmregistry:
https://registry.npmjs.org/ansi-color
I think this might be the github project: https://github.com/loopj/commonjs-ansi-color
In any case, I am unable to proceed, and all our builds fail because they are not able to fetch the given dependency.
I could perhaps use npm shrinkwrap in some way, but that depends on the modules already existing in node_modules, which I am currently missing.
So how can I force npm to use ansi-color from a different location, or ignore the dependency?
Not sure about npm 2 but you can fix this with beta npm 3. npm 3 has flat node_modules directory. So sub modules can sit in the top level. Read the Changelog.
The missing modules can be installed directly from their Github repo as a toplevel dependency in your project. If npm finds the module with the same version in node_modules directory, it won't look for it anymore in the registry.
Install npm 3:
npm install -g npm#3-latest
Then install depencies:
//install missing module from other location
npm install https://github.com/loopj/commonjs-ansi-color.git --save-dev
npm install --save-dev brunch
It looks like ansi-color is back on the npm registry ("https://registry.npmjs.org/ansi-color" is back online)

When installing a package with NPM, can you tell it to use a different version of one of its dependencies?

Say you want to install a library lib-a which has dependencies dep-1 and dep-2. If lib-a has declared in its package.json to use a version of dep-2 that is out of date (say it doesn't work on node 0.8.0 which just came out), but there is a branch of dep-2 that works with node 0.8.0 - branch name node0.8.0.
So the packages in the equation are:
git://github.com/user-a/lib-a
git://github.com/user-b/dep-1
git://github.com/user-c/dep-2
git://github.com/user-c/dep-2#node0.8.0
Is there a way to tell NPM to install lib-a, but use dep-2#node0.8.0 instead of dep-2?
With NPM you can install a specific branch of a project like this:
npm install git://github.com/user-c/dep-2#node0.8.0
And if I were to customize the package.json of lib-a, you could tell it to use dep-2#node0.8.0 like this:
{
"name": "lib-a",
"dependencies": {
"dep-1": ">= 1.5.0",
"dep-2": "git://github.com/user-c/dep-2#node0.8.0"
}
}
By modifying the package.json you can then run
npm install lib-a
and it will install the node 0.8.0 compatible dep-2 branch. But, that requires I have access to modifying lib-a, which for my specific case I don't. Technically, I could fork lib-a and make the above change to package.json. But in my specific case, lib-a is a dependency of another library, so I'd have to fork the project it's referenced in, and on and on...
So the question is, is there a way to tell NPM to install lib-a, and tell it to use the node0.8.0 branch of dep-2? Something like this:
npm install lib-a --overrides dep-2:git://github.com/user-c/dep-2#node0.8.0
That would be awesome. If it's not possible, that would be good to know so I can prepare myself to have to fork/customize the chain of projects.
NPM install syntax:
npm install (with no args in a package dir)
npm install <tarball file>
npm install <tarball url>
npm install <folder>
npm install [#<scope>/]<name> [--save|--save-dev|--save-optional] [--save-exact]
npm install [#<scope>/]<name>#<tag>
npm install [#<scope>/]<name>#<version>
npm install [#<scope>/]<name>#<version range>
npm i (with any of the previous argument usage)
so you can choose one of these methods to install your modules.
The case of the simplest way to install a specific version is this one:
npm install module#0.0.2
more info:
https://docs.npmjs.com/cli/install

Resources