Cannot assign to read only property 'exports' of object '#<Object>'
See original GitHub issueDescribe the bug
Using require
within on a CommonJS module throws this red error in the preview window.
To Reproduce Steps to reproduce the behavior:
import { storiesOf } from '@storybook/react';
import { setupGraphiQL } from '@storybook/addon-graphql';
const createQuery = require('./createQuery'); // This is the problem line
Where createQuery.js
is:
module.exports = function createQuery(operationName = 'MyQuery') {
return `...`
}
Expected behavior
I expect to be able to require
a module with module.exports
.
Screenshots
Code snippets If applicable, add code samples to help explain your problem.
System:
- OS: [MacOS]
- Device: [Macbook Pro 2018]
- Browser: [chrome]
- Framework: [e.g. react]
- Addons: [graphql]
- Version: [e.g. 4.1.7]
Additional context
Custom webpack.config.js
:
// https://storybook.js.org/configurations/custom-webpack-config/#full-control-mode
const webpack = require('webpack');
module.exports = config => {
config.devtool = 'inline-source-map';
// Needed for ./node_modules/graphiql/graphiql.css
config.module.rules.push({
test: /\.css$/,
loaders: ['style-loader', 'css-loader']
});
// Explicitly ignore `.flow` files because GraphiQL, for whatever
// insane reason, ships `.flow` files that get picked up by Webpack
// and Next.js
//
// > https://github.com/apollographql/apollo-client-devtools/pull/59/files
config.plugins.push(new webpack.IgnorePlugin(/\.flow$/));
return config;
};
Issue Analytics
- State:
- Created 5 years ago
- Reactions:24
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Cannot assign to read only property 'exports' of object ...
This error means you are trying to use commonJS inside a ES module. Instead try doing: export default lookup. When you are instantiating...
Read more >Cannot assign to read only property 'exports' of object ... - GitHub
In my react-native-web case, just use an additional webpack rule, then the TypeError: Cannot assign to read only property 'exports' of object is ......
Read more >TypeError: Cannot assign to read only property 'exports' of ...
The error is generated by Webpack and it means you are trying to use CommonJS while you need to use ES modules!
Read more >Error: Uncaught TypeError: Cannot assign to read only proper
Uncaught TypeError : Cannot assign to read only property 'exports' of object '#<Object>' at Object.<anonymous> (mdb.js:9192) at Object.
Read more >Webpack: Cannot assign to read only property 'exports'
Hi, I need to use an external library crypto when running my k6 tests. I'm using the example here: https://github.com/k6io/k6-es6 However on ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone stumbling across this, I faced the same problem after importing a NPM package to a Vue component in Storybook. Adding
sourceType: 'unambiguous'
to my babel config fixed the issue for me. Thanks to this issue https://github.com/vuejs/vue-cli/issues/2746Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!