Uncaught TypeError: __webpack_require__.r is not a function at ./node_modules/grapesjs/dist/grapes.mjs (grapes.mjs:1:1) at __webpack_require__ (bootstrap:789:1) at fn (bootstrap:150:1) at ./src/Demo/Templates/TextEditor.js (Templates.js:31:1) at __webpack_require__ (bootstrap:789:1) at fn (bootstrap:150:1) at ./src/Demo/Templates/Templates.js (Templates.css:45:1) at __webpack_require__ (bootstrap:789:1) at fn (bootstrap:150:1)
@artf pls help me solve this issue as this node modules files doesnt allows grapesjs to work in my react based project
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Version 123.0.6312.123
Reproducible demo link
Uncaught TypeError: webpack_require.r is not a function at ./node_modules/grapesjs/dist/grapes.mjs (grapes.mjs:1:1) at webpack_require (bootstrap:789:1) at fn (bootstrap:150:1) at ./src/Demo/Templates/TextEditor.js (Templates.js:31:1) at webpack_require (bootstrap:789:1) at fn (bootstrap:150:1) at ./src/Demo/Templates/Templates.js (Templates.css:45:1) at webpack_require (bootstrap:789:1) at fn (bootstrap:150:1)
Describe the bug
How to reproduce the bug?
- ...
- ...
What is the expected behavior? ...
What is the current behavior? ...
If is necessary to execute some code in order to reproduce the bug, paste it here below:
// your code here
import React, { useState, useEffect, useRef } from "react";
import gjsPresetNewsletter from "grapesjs-preset-newsletter";
import thePlugin from "grapesjs-plugin-export";
import grapesjs from "grapesjs";
import "../Templates/Templates.css";
import axios from "axios";
const InitialHtml = () => {
return `
<h1>Hi</h1>
`;
};
const TextEditor = () => {
const [editor, setEditor] = useState(null);
const [userName, setUserName] = useState(" M ");
const [userEmail, setUserEmail] = useState(" [email protected] ");
const [date, setDate] = useState(" 09-02-2024 ");
const [imagePaths, setImagePaths] = useState([]);
useEffect(() => {
const editorInstance = grapesjs.init({
container: "#editor",
fromElement: true,
plugins: [gjsPresetNewsletter, thePlugin],
pluginsOpts: {
gjsPresetNewsletter: {
showDevices: true,
},
thePlugin: {},
},
pageManager: true, // Enable PageManager
storageManager: {
autoload: true, // Load stored pages on editor initialization
autosave: true, // Autosave changes to storage
autoloadPrefix: "grapesjs-", // Prefix for autoloaded pages
},
assetManager: {
upload: "http://localhost:5000/upload",
uploadName: "file",
embedAsBase64: false,
credentials: "include",
autoAdd: 1,
// Default assets
assets: imagePaths,
storeAfterUpload: true,
// Style prefix
stylePrefix: "am-",
// Text on upload input
uploadText: "Drop files here or click to upload",
// Label for the add button
addBtnText: "Add image",
// Custom uploadFile function
uploadFile: function (e) {
var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
// ...send somewhere
// console.log(files);
var formData = new FormData();
for (var i in files) {
formData.append("file", files[i]);
}
axios
.post("http://localhost:5000/upload", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
.then((result) => {
var images = result.data.imageUrl;
editorInstance.AssetManager.add(images);
})
.catch((error) => {
console.error("Error uploading file:", error);
});
},
// * Handle the image url submit from the built-in 'Add image' form.
handleAdd: (url) => {
console.log(url);
url.startsWith("http://localhost:5000/upload")
? editorInstance.AssetManager.add(url)
: alert("Please Enter Valid URL");
},
showUrlInput: true,
},
});
editorInstance.BlockManager.add("my-block-one", {
label: "%userName%",
category: "Variables",
content: `
<span style='padding-inline: 3px'>%userName%</span>
`,
editable: true,
});
editorInstance.BlockManager.add("my-block-two", {
label: "%userEmail%",
category: "Variables",
content: `
<span style='padding-inline: 3px'>%userEmail%</span>
`,
editable: true,
});
editorInstance.BlockManager.add("my-block-three", {
label: "%date%",
category: "Variables",
content: `
<span style='padding-inline: 3px'>%date%</span>
`,
editable: true,
});
editorInstance.on("storage:store", (m) => {
console.log(m);
});
editorInstance.on("asset:upload:error", (props) => {
console.log(props, "assets upload error");
});
setEditor(editorInstance);
}, []);
useEffect(() => {
if (editor) {
editor.on("component:add", (component) => {
if (component.get("tagName") === "img") {
const imageSrc = component.get("src");
if (imageSrc !== undefined && imageSrc.substring(1, 4) !== "svg") {
setImagePaths((prevPaths) => [...prevPaths, imageSrc]);
// checkImageExistence(imageSrc);
}
}
});
const savedState = localStorage.getItem("editorState");
if (savedState) {
editor.load(savedState);
}
}
const mapObj = {
"%userName%": userName,
"%userEmail%": userEmail,
"%date%": date,
};
if (editor !== undefined) {
const html = editor?.getHtml();
const css = editor?.getCss();
const replacedHtml = html?.replace(
/%userName%|%userEmail%|%date%/gi,
(matched) => mapObj[matched]
);
// editor?.setComponents(replacedHtml);
// editor?.setStyle(css);
if (editor?.getHtml() === `<body></body>`) {
const initialHtml = InitialHtml();
editor.setComponents(initialHtml);
}
// console.log(html);
} else {
console.log("Undefined editor");
}
}, [userName, userEmail, date, editor]);
return (
<>
<table id="editor" blocks={[]}>
<thead></thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<footer className="footer sticky">
</footer>
</>
);
};
export default TextEditor;
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (3)
@artf pls help me solve this issue as this node modules files doesnt allows grapesjs to work in my react based project
Related discussion https://github.com/GrapesJS/grapesjs/discussions/5400 Please use the search before opening an issue.
Thanks for reporting this, @Mustufask.
Great question about Uncaught TypeError: webpack_require.r is not a function at ./node_modules/grapesjs/dist/grapes.mjs (grapes.mjs:1:1) at webpack_require (bootstrap:789:1) at fn (bootstrap:150:1) at ./src/Demo/Templates/TextEditor.js (Templates.js:31:1) at webpack_require (bootstrap:789:1) at fn (bootstrap:150:1) at ./src/Demo/Templates/Templates.js (Templates.css:45:1) at webpack_require (bootstrap:789:1) at fn (bootstrap:150:1). The recommended approach with StyleManager is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3759
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? chrome new versionReproducible demo link htt...
Issue #3832
The css classes are removed and the autogenerated ids for each html tags gets changed ( Example : ivj5m-2) after each reload
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link Not there De...
Issue #6706
TypeError: e.getRoot is not a function (Race condition in Style Manager)
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? All browsers (Chrome, Safari, Firefox, Edg...
Issue #6543
Panel not removed
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? chrome Reproducible demo link none Describ...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
GJS Market 2.0 - Donations, Tracking, Labels and Better Product Discovery
Weβve rolled out a new set of GrapesJS marketplace updates across GJS Market, focused on improving how creators distribute products
Tutorial
Preset DevFuture 2.0 β New Update Released
Preset continues evolving as a clean, production-ready starting point for building visual editors powered by GrapesJS
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.