nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.61k stars 2.36k forks source link

React native storybook issue #26308

Closed venky19666 closed 5 months ago

venky19666 commented 5 months ago

Current Behavior

getting error

../../node_modules/react-native/index.js:14:7: 14 │ import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo'; ╵ ~~

5:04:17 PM [vite] error while updating dependencies: Error: Build failed with 1 error: ../../node_modules/react-native/index.js:14:7: ERROR: Unexpected "typeof" at failureErrorWithLog (/home/venkatesh/workspaces/medbot/node_modules/vite/node_modules/esbuild/lib/main.js:1651:15) at /home/venkatesh/workspaces/medbot/node_modules/vite/node_modules/esbuild/lib/main.js:1059:25 at /home/venkatesh/workspaces/medbot/node_modules/vite/node_modules/esbuild/lib/main.js:1527:9 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Expected Behavior

Dummy Component should shown in storybook

GitHub Repo

No response

Steps to Reproduce

  1. I created a react-native library and configure storybook for that project.
  2. create a component and create story for that file
  3. started the storybook and I am getting error

Nx Report

NA

Failure Logs

../../node_modules/react-native/index.js:14:7:
      14 │ import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
         ╵        ~~~~~~

5:04:17 PM [vite] error while updating dependencies:
Error: Build failed with 1 error:
../../node_modules/react-native/index.js:14:7: ERROR: Unexpected "typeof"
    at failureErrorWithLog (/home/venkatesh/workspaces/medbot/node_modules/vite/node_modules/esbuild/lib/main.js:1651:15)
    at /home/venkatesh/workspaces/medbot/node_modules/vite/node_modules/esbuild/lib/main.js:1059:25
    at /home/venkatesh/workspaces/medbot/node_modules/vite/node_modules/esbuild/lib/main.js:1527:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Package Manager Version

No response

Operating System

Additional Information

{ "name": "@dummy/source", "version": "0.0.0", "license": "MIT", "private": true, "dependencies": { "@emotion/native": "^11.11.0", "@emotion/react": "^11.11.4", "@nx/devkit": "19.1.1", "axios": "^1.6.0", "express": "^4.18.1", "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.73.6", "tslib": "^2.3.0" }, "devDependencies": { "@babel/core": "^7.14.5", "@babel/preset-react": "^7.14.5", "@emotion/eslint-plugin": "^11.11.0", "@nx/detox": "19.1.1", "@nx/eslint": "19.1.1", "@nx/eslint-plugin": "19.1.1", "@nx/express": "19.1.1", "@nx/jest": "19.1.1", "@nx/js": "19.1.1", "@nx/node": "19.1.1", "@nx/playwright": "19.1.1", "@nx/plugin": "19.1.1", "@nx/react-native": "19.1.1", "@nx/storybook": "19.1.1", "@nx/vite": "19.1.1", "@nx/web": "19.1.1", "@nx/webpack": "19.1.1", "@nx/workspace": "19.1.1", "@playwright/test": "^1.36.0", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.7", "@react-native-community/cli-platform-android": "~12.3.6", "@react-native/babel-preset": "^0.73.21", "@react-native/metro-config": "^0.73.5", "@storybook/addon-essentials": "7.6.19", "@storybook/core-server": "7.6.19", "@storybook/react-vite": "7.6.19", "@svgr/webpack": "^8.0.1", "@swc-node/register": "~1.9.1", "@swc/cli": "~0.3.12", "@swc/core": "~1.5.7", "@swc/helpers": "~0.5.11", "@testing-library/jest-dom": "~6.4.2", "@testing-library/jest-native": "~5.4.3", "@testing-library/react-native": "~12.4.5", "@types/jest": "^29.4.0", "@types/node": "18.16.9", "@types/react": "~18.2.45", "@typescript-eslint/eslint-plugin": "^7.3.0", "@typescript-eslint/parser": "^7.3.0", "babel-jest": "^29.4.1", "detox": "~20.18.1", "eslint": "~8.57.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-import": "2.27.5", "eslint-plugin-jsx-a11y": "6.7.1", "eslint-plugin-playwright": "^0.15.3", "eslint-plugin-react": "7.32.2", "eslint-plugin-react-hooks": "4.6.0", "husky": "^9.0.11", "jest": "^29.4.1", "jest-circus": "^29.4.1", "jest-environment-jsdom": "^29.4.1", "jest-environment-node": "^29.4.1", "jest-react-native": "18.0.0", "nx": "19.1.1", "nx-stylelint": "^17.1.4", "postcss-styled-syntax": "^0.6.4", "prettier": "^2.6.2", "react-native-svg": "15.1.0", "react-native-svg-transformer": "1.3.0", "react-native-web": "^0.19.10", "react-refresh": "^0.10.0", "react-test-renderer": "18.2.0", "storybook": "7.6.19", "stylelint": "^16.6.1", "stylelint-config-recommended": "^14.0.0", "stylelint-config-standard": "^34.0.0", "stylelint-react-native": "^2.7.0", "ts-jest": "^29.1.0", "ts-node": "10.9.1", "typescript": "~5.4.2", "vite": "~5.0.0", "webpack-cli": "^5.1.4" }, "packageManager": "yarn@4.2.2", "scripts": { "prepare": "husky" } }

xiongemi commented 5 months ago

From the error, i think it is trying to transpile react-native package as it is since it is .js file, but it needs to use loader.

what does your .storybook/main.ts look like? it should generate something like:

import type { StorybookConfig } from '@storybook/react-webpack5';

const config: StorybookConfig = {
  stories: ['../src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
  addons: [
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
    '@nx/react/plugins/storybook',
  ],
  framework: {
    name: '@storybook/react-webpack5',
    options: {},
  },
  webpackFinal: async (config) => {
    if (config.resolve) {
      config.resolve.alias = {
        ...config.resolve.alias,
        'react-native$': 'react-native-web',
      };
      config.resolve.extensions = [
        '.web.tsx',
        '.web.ts',
        '.web.jsx',
        '.web.js',
        ...(config.resolve.extensions ?? []),
      ];
    }
    return config;
  },
};

export default config;

do you have a link to your repo?

venky19666 commented 5 months ago

I used vite. Here is the repo https://github.com/venky19666/medbot

xiongemi commented 5 months ago

@venky19666 i submit a pr to fix your storybook https://github.com/venky19666/medbot/pull/7 I also add storybook for your apps as well. to generate storybook for lib, run nx g @nx/react-native:storybook-configuration

github-actions[bot] commented 4 months ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.