-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught TypeError: Cannot redefine property: render #104
Comments
I've attempted to use the 'next-remove-imports', but I'm still getting 'Cannot redefine property: render' error. My next.config.js:
|
// next.config.js
const removeImports = require('next-remove-imports')();
module.exports = (phase, { defaultConfig }) => {
return removeImports({
...defaultConfig
});
}; // next.config.js
const removeImports = require('next-remove-imports')({
test: /node_modules([\s\S]*?)\.(tsx|ts|js|mjs|jsx)$/,
matchImports: "\\.(less|css|scss|sass|styl)$"
});
module.exports = removeImports({
webpack(config, options) {
return config
},
}); // next.config.js
const removeImports = require('next-remove-imports')()
module.exports = removeImports({
webpack(config, options) {
return config
},
}); |
OK, I found a solution by myself. If other people get the same issue, that's what I did:
|
I have a NextJS project and faced the same issue. For example: Importing components from |
Had this same issue when using Astro. Changing imports to import { Sketch } from "@uiw/react-color/src/index"; |
Just to clarify, this problem is nothing to do with Next.js or Jest. The problem is that the CommonJS build is broken, so anything which imports the CommonJS build will get this error. This can be confirmed by creating the following simple CommonJS file, and seeing the error. const reactColor = require("@uiw/react-color");
console.log(reactColor);
// Uncaught TypeError: Cannot redefine property: render The reason this breaks is because in the package export, every sub package is exported with When this compiles to CommonJS, it ends up like this. Each of these var _reactColorSwatch = _interopRequireWildcard(require("@uiw/react-color-swatch"));
Object.keys(_reactColorSwatch).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _reactColorSwatch[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _reactColorSwatch[key];
}
});
});
var _reactColorWheel = _interopRequireWildcard(require("@uiw/react-color-wheel"));
Object.keys(_reactColorWheel).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _reactColorWheel[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _reactColorWheel[key];
}
});
}); You cannot use The solution is to avoid exporting sub packages like this, or at least being careful that each sub package defines unique exports. I have added a PR (#140) which addresses this. As a super hacky fix, I have added a patch to my project which adds the var _reactColorWheel = _interopRequireWildcard(require("@uiw/react-color-wheel"));
Object.keys(_reactColorWheel).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _reactColorWheel[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
+ configurable: true,
get: function get() {
return _reactColorWheel[key];
}
});
}); |
NextJS (tried to turn off SSR, checked for
window
variable etc) - no difference. Do you have any advises here? Thank you in advanceThe text was updated successfully, but these errors were encountered: