question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot assign to read only property 'exports' of object '#<Object>'

See original GitHub issue

Describe 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

screen shot 2019-01-18 at 3 55 14 pm

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:closed
  • Created 5 years ago
  • Reactions:24
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

28reactions
gilesbutlercommented, Oct 23, 2019

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/2746

26reactions
stale[bot]commented, Aug 7, 2019

Hey 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found