Issue #2018Opened May 15, 2019by nternouski2 reactions

BUG When import as module Angular 6

Question

in Version: "grapesjs": "^0.14.61", "grapesjs-preset-newsletter": "^0.2.20",

i import the script as:

import grapesjs from "grapesjs";
import grapesjsPresetNewsletter from "grapesjs-preset-newsletter";

and the context is the code:

 ngOnInit() {
	this.editor = grapesjs.init({
		container: "#gjs",
		components: `<div class="txt-red">Hello world!</div>`,
		style: ".txt-red{color: red}",
		plugins: [
			// "gjs-preset-newsletter"
			grapesjsPresetNewsletter
		],
		pluginsOpts: {
			"gjs-preset-newsletter": {
				modalTitleImport: "Importar Template",
				importPlaceholder: "Inserte aquí el HTML y CSS inline",
				inlineCss: true,
			},
		}
	});
}

And only on build, the console print:

main.011758c7e31c6528fe91.js:1 ERROR TypeError: i is not a function
    at 15.aacc28347512f1c58ef9.js:1
    at 15.aacc28347512f1c58ef9.js:1
    at 15.aacc28347512f1c58ef9.js:1
    at Array.forEach (<anonymous>)
    at Object.init (15.aacc28347512f1c58ef9.js:1)
    at e.ngOnInit (15.aacc28347512f1c58ef9.js:1)
    at main.011758c7e31c6528fe91.js:1
    at main.011758c7e31c6528fe91.js:1
    at bo (main.011758c7e31c6528fe91.js:1)
    at qo (main.011758c7e31c6528fe91.js:1)

Please Help me. Thanks for your time.

Answers (3)

joshberryAugust 10, 20191 reactions

@nternouski I'm guessing you needed to include the gjs-preset-newsletter script in the scripts section of your build in angular.json.

"scripts": [
    "./node_modules/grapesjs/dist/grapes.min.js",
    "./node_modules/grapesjs-preset-webpage/dist/grapesjs-preset-webpage.min.js",
    "./node_modules/grapesjs-blocks-bootstrap/dist/grapesjs-blocks-bootstrap4.min.js"
]

Any plugins you want to use need to be included here or the angular build won't know to include them.

joshberryAugust 11, 20191 reactions

If you don't add it globally, you'll need to manually register the plugin with grapesjs.

import grapesjs from "grapesjs";
import grapesjsPresetNewsletter from "grapesjs-preset-newsletter";

grapesjs.plugins.add('grapesjs-preset-newsletter', grapesjsPresetNewsletter );

Then, be sure to use the ID you configured and not the variable name when initializing.

ngOnInit() {
  this.editor = grapesjs.init({
    container: "#gjs",
    plugins: [ "gjs-preset-newsletter" ]
  });
}
artfMay 19, 20190 reactions

Hi @nternouski, unfortunately, that plugin still uses the old exporting, so you have to use it like this:

import grapesjs from "grapesjs";
import "grapesjs-preset-newsletter";
...
grapesjs.init({
 ...
 plugins: ["gjs-preset-newsletter"],
 ...
})

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.