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.

Using lerna, source-loader cannot resolve packages

See original GitHub issue

Describe the bug

WARNING in ./packages/common/src/AntdCommonButton.stories.tsx 16:2
Module parse failed: Unexpected token (16:2)
File was processed with these loaders:
 * ./node_modules/@storybook/source-loader/dist/index.js
You may need an additional loader to handle the result of these loaders.
|     title: 'Example/AntdCommonButton',
|     component: AntdCommonButton,
> } as Meta;
| 
| export const basic = () => <AntdCommonButton type="primary" />;
 @ \.)(?=.)[^\/]*?\.stories\.(js|jsx|ts|tsx))$ (./packages sync ^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^\/]*?\.stories\.(js|jsx|ts|tsx))$) ./common/src/AntdCommonButton.stories.tsx
 @ ./.storybook/generated-stories-entry.js
 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/storybook-init-framework-entry.js ./node_modules/@storybook/addon-docs/dist/frameworks/common/config.js-generated-other-entry.js ./node_modules/@storybook/addon-docs/dist/frameworks/react/config.js-generated-other-entry.js ./node_modules/@storybook/addon-links/dist/preset/addDecorator.js-generated-other-entry.js ./node_modules/@storybook/addon-actions/dist/preset/addDecorator.js-generated-other-entry.js ./node_modules/@storybook/addon-actions/dist/preset/addArgs.js-generated-other-entry.js ./node_modules/@storybook/addon-backgrounds/dist/preset/defaultParameters.js-generated-other-entry.js ./.storybook/preview.js-generated-config-entry.js ./.storybook/generated-stories-entry.js ./node_modules/webpack-hot-middleware/client.js?reload=true&quiet=false&noInfo=undefined

Expected behavior Hope the packages directory can work If it is in the src directory, it can work.

Screenshots image

Code snippets https://github.com/lucaslz2020/cra-ts-lerna-antd

System:

    "@babel/core": "^7.11.4",
    "@storybook/addon-actions": "^6.0.17",
    "@storybook/addon-essentials": "^6.0.17",
    "@storybook/addon-links": "^6.0.17",
    "@storybook/node-logger": "^6.0.17",
    "@storybook/preset-ant-design": "0.0.1",
    "@storybook/preset-create-react-app": "^3.1.4",
    "@storybook/react": "^6.0.17",
    "babel-loader": "^8.1.0",
    "css-loader": "^4.2.2",
    "lerna": "^3.18.3",
    "less": "^3.12.2",
    "less-loader": "^5.0.0",
    "react-is": "^16.13.1",
    "style-loader": "^1.2.1"

Additional context https://github.com/storybookjs/storybook/issues/10347

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
drphelpscommented, Sep 9, 2020

I had the same issue in a monorepo with workspaces. It should be possible to tweak the Webpack config so that your package dirs are transpiled, something like the following:

module.exports = {
  ...

  webpackFinal: (config) => {
    const {
      module: {
        rules: [, , , , , , { oneOf }],
      },
    } = config;

    const babelLoader = oneOf.find(({ test }) => new RegExp(test).test('.ts'));

    // transpile shared modules from any package
    babelLoader.include = /packages\/(.*)\/src/;

    return config;
  },
};
1reaction
mattfeltencommented, Sep 29, 2020

Figured it out. For whatever reason this config had an extra item in the array. I needed an extra comma.

console.log('config.module.rules', config.module.rules);

^ was able to show me how many rules I had and where oneOf was.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting | Lerna
Troubleshooting. This document contains solutions for certain issues our users encountered in the past while using Lerna.
Read more >
@storybook/source-loader | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
node.js - lerna + webpack + babel-loader issue - Stack Overflow
One nice thing about using Lerna is you can pull devDependencies up to the repo root to factor them out of the individual...
Read more >
Managing Monorepo using Lerna and Yarn workspaces
This article shows how to manage multiple packages in a single repository. What is Monorepo? In this article, what we call "Monorepo" is...
Read more >
Setting up a monorepo with Lerna for a TypeScript project
js projects with npm and Git. Lerna has two modes: fixed and independent. Fixed mode keeps all versions of packages at the same...
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