Skip to content
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

Cannot import modules from modules CommonJS exports #7176

Closed
tanint opened this issue Jun 24, 2019 · 3 comments
Closed

Cannot import modules from modules CommonJS exports #7176

tanint opened this issue Jun 24, 2019 · 3 comments

Comments

@tanint
Copy link

tanint commented Jun 24, 2019

Describe the bug
I build a component in react using NextJS and use next-routes as the router. So I create routes.js inside project and export by CommonJS syntax for compatible with custom server.js to require modules.

The component in the project that runs by NextJS works well with import syntax. But the same component that runs in the storybook environment cannot find modules that export from CommonJS file (routes.js)

To Reproduce
Steps to reproduce the behavior:

  1. Import function that export from CommonJS file
  2. Render component in the story file

Expected behavior
I think this should work in the storybook environment same the NextJS environment

Code snippets

routes.js

const routes = require('next-routes')

module.exports = routes()
.add('about')

Hello.js

import { Link } from './routes'

export default function Home () {
   return (
     <div>
        <Link to="about">
           <a>About</a>
        </Link>
     </div>
  )
}

And show error like this in Storybook console

WARNING in ./components/Home.js "export 'Link' was not found in '../router'

System:

  • OS: MacOS
  • Device: Macbook Pro Late 2013
  • Browser: [Chrome
  • Framework: react
  • Version: 5.1.9
@adamchenwei
Copy link

adamchenwei commented Jul 15, 2019

I may have the similar issue. my js file is a commonjs component.
i.e.

(function (_, abc) {
  ...
  return _;
}(module.exports, require('abc')));

But importing it cause the storybook to yell
`Module not found: Error: Can't resolve 'the-component' in 'my/custom/route'

even route is correctly defined.

Wonder if there is anything needed to be done in the webpack.config.js in .storybook/ folder so maybe storybook do not compile it? not really sure what is the issue at this point.

@stale
Copy link

stale bot commented Aug 8, 2019

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Aug 8, 2019
@stale
Copy link

stale bot commented Sep 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!

@stale stale bot closed this as completed Sep 7, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants