Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Storyshots gives "implicit any" / "can't find module" errors #1181

Closed
su-narthur opened this issue Jun 2, 2017 · 4 comments
Closed

Storyshots gives "implicit any" / "can't find module" errors #1181

su-narthur opened this issue Jun 2, 2017 · 4 comments

Comments

@su-narthur
Copy link
Contributor

I'm trying to set up Storyshots in my project. Storyshots.test.ts looks like this:

import initStoryshots from '@storybook/addon-storyshots/'

initStoryshots();

When I run the tests, the test runner gives me this error:

Cannot find module '../../package' from 'node.js'
  
  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
  at Object.<anonymous> (node_modules/babel-core/lib/api/node.js:60:16)

My IDE highlights the import statement in Storyshots.test.ts with this error:

TS7016:Could not find a declaration file for module '@storybook/addon-storyshots/'. '[path to project]/node_modules/@storybook/addon-storyshots/dist/index.js' implicitly has an 'any' type.

Here are the versions I'm on:

  "dependencies": {
    "@types/jest": "^19.2.3",
    "@types/node": "^7.0.18",
    "@types/react": "^15.0.24",
    "@types/react-dom": "^15.5.0",
    "@types/react-router-dom": "^4.0.4",
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "react-relay": "^1.0.0",
    "react-router-dom": "^4.1.1",
    "styled-components": "^2.0.0",
    "ts-loader": "^2.1.0",
    "webpack": "^2.6.0"
  },
  "devDependencies": {
    "@storybook/addon-actions": "^3.0",
    "@storybook/addon-centered": "^3.0.0",
    "@storybook/addon-storyshots": "^3.0.0",
    "@storybook/react": "^3.0",
    "react-scripts-ts": "2.0.1",
    "react-test-renderer": "^15.5.4"
  },

How can I fix this?

@HBCharles
Copy link

What was your fix ? I'm also having the issue.

@mattleff
Copy link
Contributor

mattleff commented Jun 7, 2017

@HBCharles There were several issues that we worked through. For reference we are using react-scripts-ts.

TS7016:Could not find a declaration file for module...

This is due to using noImplicitAny but not having types for Storyshots. Hopefully better types will come with #1166. Our solution for now is to have a declarations.d.ts:

declare module '@storybook/addon-storyshots'

Cannot find module '../../package' from 'node.js'

This issue was the trickiest. Ultimately the fix I found is wmonk/create-react-app-typescript#78. I'm using a fork until/if that pull is merged.

Hope this helps!

@shilman
Copy link
Member

shilman commented Jun 8, 2017

@mattleff @HBCharles Re #1166 we have DefinitelyTyped defs now at "@types/storybook__react": "^3.0.0". @joscha is in the process of doing the rest, so if you have any feedback please let us know!

@mattleff
Copy link
Contributor

mattleff commented Jun 8, 2017

@shilman Thanks for that, it's great! Until all the addons have types the declare module ... is still necessary if using noImplicitAny.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants