I have (followed this https://medium.com/@camiloht23/integraci%C3%B3n-de-grapesjs-con-angular-11ebf3bb80c5) installed and trying to import GrapesJS in Angular. But I am getting an error as "Could not find a declaration file for module 'node_modules/grapesjs'. 'app-test/node_modules/grapesjs/dist/grapes.min.js' implicitly has an 'any' type.
Try npm install @types/grapesjs
if it exists or add a new declaration (.d.ts) file containing declare module 'node_modules/grapesjs';
". How to clear the error?
How to integrate GrapesJS with Angular?
5.3k views Asked by Nivetha AtThere are 4 answers
This is a typescript issue.
Seems you are using typescript, but GrapesJS doesn't have type definitions yet.
A quick fix for this is to disable this check by adding a disable rule before the import
// @ts-ignore
import * as grapesjs from 'grapesjs';
A better solution would be to create a types.d.ts
file in the root of your project with declare module 'grapesjs'
in it and then making sure this is included in your typescript transpile step. This is a little trickier than the disable rule above if you're unfamiliar with Typescript.
If you want a better understanding of this issue, I would recommend you search your error text and find some typescript stack overflow with more solutions. You can also consult the Typescript documentation here https://www.typescriptlang.org/docs/handbook/2/type-declarations.html
In the near future, we may have types for GrapesJS, current discourse is happening here:
Use:
npm i grapesjs
then add to angular.json
"projects": {
...,
"architect":{
...,
"options": {
"build": {
...,
"styles": {
...,
"node_modules/grapesjs/dist/css/grapes.min.css" //<-- Add this
},
"scripts": {
...,
"node_modules/grapesjs/dist/grapes.min.js", //<- Add this
}
}
}
}
}
And finally add to your component.ts something like this
import 'grapesjs-preset-webpage';
import grapesjs from 'grapesjs';
...
var editor = grapesjs.init({
container : '#gjs',
components: '<div class="txt-red">Hello world!</div>',
style: '.txt-red{color: red}',
});
Step1: Install using
Step2: Add Styles and scripts to angular.json
Step3: Refrence
Create a file name typings.d.ts in the /src/ directory if it does not exists. Open the file typings.d.ts and add the following content:
Step4: Now open your component.ts file and initialize the library:
In your component.html
Note: Its redundant to import grapesjs in the component file.