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

svelte: Unable to load an external svelte components (.svelte files) #9542

Closed
soullivaneuh opened this issue Jan 19, 2020 · 4 comments
Closed

Comments

@soullivaneuh
Copy link

Describe the bug
I cannot import svelte module from external components library like this one: https://gitlab.com/nexylan/svelty

To Reproduce
Steps to reproduce the behavior:

  1. Follow Svelty installation (package.json edit). (For my case, I put it on dependencies because I want it installed while my library is added, but devDependencies causes the same issue).
  2. Try to import and use the Copy component.
  3. Launch test and/or build

You will have the following error:

    Cannot find module 'svelty' from 'RideStepPlace.svelte'

      1 | <script>
    > 2 |   import { Copy } from 'svelty';
        |                ^
      3 | 
      4 |   export let ride;
      5 |   export let step;

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
      at Object.<anonymous> (src/components/RideStepPlace.svelte:2:16)

Expected behavior
The module should be loaded

Please note that the library works well with the roll-up component build. This is only not working with Storybook.

System:
Please paste the results of npx -p @storybook/cli@next sb info here.

Environment Info:

  System:
    OS: Linux 4.19 Manjaro Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  Binaries:
    Node: 12.11.1 - /usr/bin/node
    Yarn: 1.19.1 - /usr/bin/yarn
    npm: 6.12.1 - /usr/bin/npm
  Browsers:
    Firefox: 70.0
  npmPackages:
    @storybook/addon-a11y: ^5.3.6 => 5.3.6 
    @storybook/addon-actions: ^5.3.6 => 5.3.6 
    @storybook/addon-knobs: ^5.3.6 => 5.3.6 
    @storybook/addon-links: ^5.3.6 => 5.3.6 
    @storybook/addon-notes: ^5.3.6 => 5.3.6 
    @storybook/addon-storyshots: ^5.3.6 => 5.3.6 
    @storybook/addon-storysource: ^5.3.6 => 5.3.6 
    @storybook/addon-viewport: ^5.3.6 => 5.3.6 
    @storybook/addons: ^5.3.6 => 5.3.6 
    @storybook/svelte: ^5.3.6 => 5.3.6 
@soullivaneuh
Copy link
Author

Here is the workaround I found:

cd node_modules/svelty
npm install
# Build svelte files onto dist js files. Needed for StoryBook
# @see https://github.com/storybookjs/storybook/issues/9542
npm run build-components
cd -

Put that on the install script, it generate the compiled js file to get StoryBook working.

Still, it is possible to load .svelte files directly with rollup and webpack.

Maybe a missing configuration/loader on the Storybook compiler? Which one do you use?

@pocka
Copy link
Contributor

pocka commented Jan 22, 2020

@soullivaneuh
Your package's main and module fields rely on dist/ which does not exist. Try using a prepare hook instead of prepublishOnly. The prepublishOnly hook won't run when the package is installed as git dependency.

If you want Storybook to resolve to the file specified in package.json#svelte, configuring resolve.mainFields would help.

// main.js
module.exports = {
  webpackFinal(config) {
    return {
      ...config,
      resolve: {
        ...config.resolve,
        mainFields: ['svelte', 'browser', 'module', 'main']
    }
  }
}

@stale
Copy link

stale bot commented Feb 12, 2020

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 Feb 12, 2020
@stale
Copy link

stale bot commented Mar 13, 2020

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!

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