Fail to load storybook everytime - reactjs

Failed to load storybook, everytime,I run npm run storybook
I have ever tried to clear the npm-cache as well, it didn't worked out.
I am using latest version of storybook - v6.5.4
Error:
triggerUncaughtException(err, true /* fromPromise */);
^
[Error: EBUSY: resource busy or locked, open 'C:\Users\soham.nandi\Desktop\analytics-storybook\node_modules.cache\storybook\dev-server\325c8f456729b912b0d2134054eb7448-41ac79ddc5290d504ad69ef1fe8200a7'] {
errno: -4082,
code: 'EBUSY',
syscall: 'open',
path: 'C:\Users\soham.nandi\Desktop\analytics-storybook\node_modules\.cache\storybook\dev-server\325c8f456729b912b0d2134054eb7448-41ac79ddc5290d504ad69ef1fe8200a7'
main.js
module.exports = {
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.#(js|jsx|ts|tsx)"],
addons: [
"#storybook/addon-links",
"#storybook/addon-essentials",
"#storybook/addon-interactions",
"#storybook/preset-create-react-app",
"#storybook/addon-a11y",
],
framework: "#storybook/react",
core: {
builder: "#storybook/builder-webpack5",
},
features: {
storyStoreV7: true,
},
};
main.js
import { Suspense } from "react";
import { initReactI18next } from "react-i18next";
import i18n from "i18next";
import HttpApi from "i18next-http-backend";
import { LANGUAGES, TIMEZONES } from "../src/constants";
import "../node_modules/bootstrap/scss/bootstrap.scss";
import "../src/styles/index.scss";
i18n
.use(initReactI18next)
.use(HttpApi)
.init({
supportedLngs: LANGUAGES,
fallbackLng: "en-US",
lng: "en-US",
backend: {
loadPath: "/assets/locals/{{lng}}/translation.json",
},
react: { useSuspence: false },
});
export const globalTypes = {
locale: {
name: "Change Language",
description: "Change Language Support for the application",
defaultValue: "en-US",
toolbar: {
icon: "lightning",
items: LANGUAGES,
showName: true,
},
},
timezone: {
name: "Change Timezone",
description: "Change Timezone Support for the application",
defaultValue: "Asia/Kolkata",
toolbar: {
icon: "time",
items: TIMEZONES,
showName: true,
},
},
};
export const decorators = [
(Story, context) => {
i18n.changeLanguage(context.globals.locale);
return (
<div style={{ margin: "3em" }}>
<Suspense fallback={<div>Loading...</div>}>
<Story />
</Suspense>
</div>
);
},
];
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
options: {
storySort: (a, b) =>
a.title === b.title
? 0
: a.id.localeCompare(b.id, undefined, { numeric: true }),
},
};
package.js
{
"name": "analytics-storybook",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"bootstrap": "^5.1.3",
"date-fns": "^2.28.0",
"date-fns-tz": "^1.3.4",
"i18next": "^21.8.2",
"i18next-http-backend": "^1.4.0",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-bootstrap": "^2.4.0",
"react-datepicker": "^4.7.0",
"react-dom": "^17.0.2",
"react-i18next": "^11.16.9",
"react-scripts": "^5.0.1",
"react-select": "^5.3.2",
"react-table": "^7.8.0",
"react-table-sticky": "^1.1.3",
"sass": "^1.51.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"eject": "react-scripts eject",
"lint": "eslint .",
"lint:fix": "eslint --fix",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#storybook/addon-a11y": "^6.5.4",
"#storybook/addon-actions": "^6.5.4",
"#storybook/addon-essentials": "^6.5.4",
"#storybook/addon-interactions": "^6.5.4",
"#storybook/addon-links": "^6.5.4",
"#storybook/builder-webpack5": "^6.5.4",
"#storybook/manager-webpack5": "^6.5.4",
"#storybook/node-logger": "^6.5.4",
"#storybook/preset-create-react-app": "^4.1.1",
"#storybook/react": "^6.5.4",
"#storybook/testing-library": "^0.0.11",
"babel-plugin-named-exports-order": "^0.0.2",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-storybook": "^0.5.12",
"identity-obj-proxy": "^3.0.0",
"prop-types": "^15.8.1",
"webpack": "^5.72.1"
}
}
npm version: v8.10.0
node version: v16.15.0

Try changing your node version to LTS.

I got the solution, it was due to some Hp driver. I uninstalled it, it started working
Driver name: HP Wolf Security
https://support.aspnetzero.com/QA/Questions/11057/Error-EBUSY-resource-busy-or-locked-when-running-npm-run-create-bundles

Related

React App Keep Reloading until it get crashed

I am new to react js, I created a react app, and whenever I try to open the app it continuously reloads. can anyone help me in this? i tried but unable to find out any perfect solution.
Any solution?
package.json
{
"name": "sf",
"author": "KKK Team",
"version": "0.0.1",
"private": true,
"homepage": "/sfrs",
"scripts": {
"start": "env-cmd -f .env.development react-scripts start",
"build:development": "env-cmd -f .env.development react-scripts build",
"build:nonprod": "env-cmd -f .env.nonprod react-scripts build",
"build:production": "env-cmd -f .env.production react-scripts build",
"build": "react-scripts build",
"test": "jest --verbose",
"test:dev": "jest",
"test:watch": "jest --silent --watchAll",
"test:coverage": "jest --silent --coverage",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"dependencies": {
"#date-io/date-fns": "^1.3.13",
"#emotion/react": "^11.7.1",
"#emotion/styled": "^11.6.0",
"#material-table/core": "^0.2.20",
"#mui/icons-material": "^5.3.1",
"#mui/lab": "^5.0.0-alpha.66",
"#mui/material": "^5.3.1",
"#mui/styles": "^5.3.0",
"axios": "^0.25.0",
"buffer": "^6.0.3",
"clsx": "^1.1.1",
"crypto-browserify": "^3.12.0",
"env-cmd": "^10.1.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"msal": "^1.4.16",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-perfect-scrollbar": "^1.5.8",
"react-redux": "^7.2.6",
"react-router": "^6.2.1",
"react-router-dom": "^6.2.1",
"recompose": "^0.30.0",
"redux": "^4.1.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.4.1",
"stream-browserify": "^3.0.0",
"sweetalert2": "^11.4.8",
"sweetalert2-react-content": "^4.2.0",
"util": "^0.12.4",
"validator": "^13.7.0",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"#testing-library/jest-dom": "^5.16.1",
"#testing-library/react": "^12.1.2",
"#testing-library/user-event": "^13.5.0",
"eslint": "^7.11.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"husky": "^4.2.3",
"jest-canvas-mock": "^2.3.1",
"lint-staged": "^10.0.8",
"prettier": "^1.19.1",
"react-error-overlay": "^6.0.9",
"react-scripts": "4.0.3"
},
"jest": {
"setupFiles": [
"jest-canvas-mock"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run test"
}
},
"lint-staged": {
"src/**/*.{js,jsx,json,css}": [
"prettier --write",
"eslint --fix"
]
},
"babel": {
"presets": [
"#babel/preset-react",
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"#babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
},
"resolutions": {
"react-error-overlay": "6.0.9"
}
}
I am using MUI 5. I have tried with upgrading and degrading the node version but unable to solve the issue.
app.jsx
import 'react-perfect-scrollbar/dist/css/styles.css';
import React, { useEffect } from 'react';
import { useRoutes } from 'react-router-dom';
import _ from 'lodash';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { ThemeProvider } from '#mui/material';
import AuthProvider from './components/auth_provider';
import GlobalStyles from './components/globalstyles';
import theme from './theme/theme';
import AuthenticationProgressLoader from './components/authentication_progress_loader';
import UnAuthorized from './components/unauthorized';
import routeManager from './lib/route.manager';
import Alerts from './components/c_alert';
import PageProgress from './components/c_page_progress';
import PermissionManager from './lib/permission.manager';
const App = props => {
const {
userAccount,
userPermissions,
graphProfile,
routesConfig,
alerts,
isPageLoader
} = props;
const routing = useRoutes(routesConfig || []);
useEffect(() => {
if (
!_.isEmpty(userPermissions) &&
PermissionManager.isUserMerchant() &&
_.isEmpty(routesConfig)
) {
routeManager.dispatchRoutes();
}
}, [routesConfig, userPermissions]);
return !userPermissions ||
(!_.isEmpty(userPermissions) && !PermissionManager.isUserMerchant()) ? (
<UnAuthorized />
) : (
<ThemeProvider theme={theme}>
<GlobalStyles />
{!_.isEmpty(alerts.message) && <Alerts />}
{isPageLoader && <PageProgress />}
{userAccount && graphProfile && !_.isEmpty(userPermissions) ? (
routing
) : (
<AuthenticationProgressLoader />
)}
</ThemeProvider>
);
};
App.propTypes = {
// eslint-disable-next-line react/forbid-prop-types
userAccount: PropTypes.object,
// eslint-disable-next-line react/forbid-prop-types
graphProfile: PropTypes.object,
// eslint-disable-next-line react/forbid-prop-types
userPermissions: PropTypes.object,
// eslint-disable-next-line react/forbid-prop-types
routesConfig: PropTypes.array,
// eslint-disable-next-line react/forbid-prop-types
alerts: PropTypes.object,
isPageLoader: PropTypes.bool
};
App.defaultProps = {
userAccount: {},
graphProfile: {},
userPermissions: {},
routesConfig: [],
alerts: {},
isPageLoader: false
};
function mapStatesToProps(state) {
const { userPermissions, graphProfile, userAccount } = state.auth;
const { routesConfig } = state.routes;
const { alerts } = state;
const { isPageLoader } = state.pageProgress;
return {
userPermissions,
graphProfile,
userAccount,
routesConfig,
alerts,
isPageLoader
};
}
const authApp = AuthProvider(App);
const connectedApp = connect(mapStatesToProps, null)(authApp);
// eslint-disable-next-line
export { connectedApp as App };

Rollup.js can not detect default exports when trying to build component library with React.js

I am trying to create component library with React.js, I am using Rollup.js for this.
When I am building the app, I see this error in the console. It seems Rollup can not detect default exports, I tried to add a .babelrc file configuration but unfortunately it did not work.
What am I doing wrong and how can this problem be solved?
//rollup.config.js
import babel from 'rollup-plugin-babel';
import resolve from '#rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import commonjs from '#rollup/plugin-commonjs';
export default [
{
input: './src/index.js',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
}
],
plugins: [
postcss({
plugins: [],
minimize: true,
}),
babel({
exclude: "node_modules/**",
presets: ["#babel/preset-react"],
}),
external(),
resolve(),
terser(),
]
}
];
//package.json
{
"name": "test",
"version": "0.1.0",
"private": false,
"dependencies": {
"#babel/preset-stage-1": "^7.8.3",
"#rollup/plugin-commonjs": "^21.0.3",
"#rollup/plugin-replace": "^2.4.2",
"#testing-library/jest-dom": "^5.16.3",
"#testing-library/react": "^12.1.4",
"#testing-library/user-event": "^13.5.0",
"babel-preset-latest": "^6.24.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"react-transform-hmr": "^1.0.4",
"typescript": "^4.6.3",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "tsc",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"build-lib": "rollup -c"
},
"files": [
"dist"
],
"main": "dist/index.js",
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"overrides": [
{
"files": [
"**/*.stories.*"
],
"rules": {
"import/no-anonymous-default-export": "off"
}
}
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/plugin-external-helpers": "^7.16.7",
"#babel/preset-react": "^7.16.7",
"#rollup/plugin-node-resolve": "^11.2.1",
"#storybook/addon-actions": "^6.4.19",
"#storybook/addon-essentials": "^6.4.19",
"#storybook/addon-interactions": "^6.4.19",
"#storybook/addon-links": "^6.4.19",
"#storybook/builder-webpack5": "^6.4.19",
"#storybook/manager-webpack5": "^6.4.19",
"#storybook/node-logger": "^6.4.19",
"#storybook/preset-create-react-app": "^4.1.0",
"#storybook/react": "^6.4.19",
"#storybook/testing-library": "^0.0.9",
"rollup": "^2.70.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"semantic-release": "^19.0.2",
"webpack": "^5.70.0"
}
}
The error is telling you what you need to know. To explain what that means, there is no export default ... in react-dom (you can verify this by looking at the source code).
There are several ways to fix this:
Play around with some of the #rollup/plugin-commonjs settings. Sorry I can't tell you which one will work, maybe start with defaultIsModuleExports.
Import the method that you need. With react-dom, you're likely only using render, so import it like this: import { render } from 'react-dom'
Import everything and alias as ReactDOM: import * as ReactDOM from 'react-dom'

How to use CSS modules with parcel?

When I try to do this:
// index.js
import * as classes from './index.module.css'
I get this:
Error: Bundles must have unique names
// .parcelrc
{
"extends": "#parcel/config-webextension"
}
// babel.config.js
module.exports = {
plugins: [
[
"#babel/plugin-proposal-decorators",
{
legacy: true,
},
],
[
"#babel/plugin-proposal-class-properties",
{
loose: true,
},
],
],
presets: [
[
"#babel/preset-env",
{
targets: {
node: "current",
},
loose: true,
},
],
"#babel/preset-react",
],
}
// package.json
{
"private": true,
"scripts": {
"build": "parcel build source/manifest.json --no-content-hash --no-source-maps --dist-dir distribution --no-cache --detailed-report 0",
"lint": "run-p lint:*",
"lint-fix": "run-p 'lint:* -- --fix'",
"lint:css": "stylelint source/**/*.css",
"lint:js": "xo",
"eslint": "eslint source/**/*.js source/**/*.jsx",
"test": "run-p lint:* build",
"watch": "parcel watch source/manifest.json --dist-dir distribution --no-cache --no-hmr"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"source/**/*.{js,jsx}": [
"eslint",
"prettier --write"
],
"source/**/*.css": [
"prettier --write"
]
},
"browserslist": [
"last 1 Chrome version",
"last 1 Firefox version"
],
"xo": {
"envs": [
"browser"
],
"rules": {
"no-unused-vars": [
"error",
{
"varsIgnorePattern": "browser"
}
]
}
},
"stylelint": {
"extends": "stylelint-config-xo"
},
"dependencies": {
"#reduxjs/toolkit": "^1.8.0",
"bootstrap": "^5.1.3",
"react": "^17.0.2",
"react-bootstrap": "^2.2.1",
"react-bootstrap-typeahead": "^6.0.0-alpha.9",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-toastify": "^8.2.0",
"redux-saga": "^1.1.3",
"webext-options-sync": "^3.0.1",
"webextension-polyfill": "^0.8.0"
},
"devDependencies": {
"#babel/core": "^7.17.7",
"#babel/eslint-parser": "^7.17.0",
"#babel/plugin-proposal-class-properties": "^7.16.7",
"#babel/plugin-proposal-decorators": "^7.17.2",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
"#parcel/config-webextension": "^2.3.2",
"#parcel/transformer-image": "^2.3.2",
"axios": "^0.26.1",
"eslint": "^8.11.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-react": "^7.29.3",
"husky": "4",
"lint-staged": "^12.3.7",
"npm-run-all": "^4.1.5",
"parcel": "^2.3.2",
"postcss": "^8.0.0",
"postcss-modules": "^4.3.0",
"prettier": "^2.5.1",
"process": "^0.11.10",
"rollup-plugin-import-css": "^3.0.3",
"stylelint": "^14.5.3",
"stylelint-config-xo": "^0.20.1",
"xo": "^0.48.0"
},
"webExt": {
"sourceDir": "distribution"
}
}
Error stacktrace
Error: Bundles must have unique names
AssertionError [ERR_ASSERTION]: Bundles must have unique names
at BundlerRunner.nameBundles
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/requests/BundleGraphRequest.js:343:23)
at async BundlerRunner.bundle
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/requests/BundleGraphRequest.js:286:5)
at async RequestTracker.runRequest
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/RequestTracker.js:725:20)
at async Object.run
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/requests/ParcelBuildRequest.js:62:7)
at async RequestTracker.runRequest
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/RequestTracker.js:725:20)
at async Parcel._build
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/Parcel.js:397:11)
at async Parcel._startNextBuild
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/Parcel.js:298:24)
at async $b0fd219fea43bcac$export$2e2bcd8739ae039._runFn
(/Users/Goldy/apps/web-extension/node_modules/#parcel/utils/lib/index.js:32645:13)
at async $b0fd219fea43bcac$export$2e2bcd8739ae039._next
(/Users/Goldy/apps/web-extension/node_modules/#parcel/utils/lib/index.js:32638:9)
What am I missing here?
I also tried to add the following file with no effect:
// .postcssrc.js
module.exports = {
modules: true,
plugins: {
"postcss-modules": {
generateScopedName: "[folder]__[local]___[hash:base64:6]",
},
},
}

Cannot read property 'name' of undefined Occurred while linting in React

I have this really weird "bug" I guess you can call it with eslint when I try and run yarn lint
$ tsc --noEmit && eslint src/**/*.ts{,x}
For some reason it fails with
Oops! Something went wrong! :(
ESLint: 7.32.0
TypeError: Cannot read property 'name' of undefined
Occurred while linting /Users/Reynaldo/Documents/cafemat/src/hooks/useFirebase.ts:13
at ExpressionStatement (/Users/Reynaldo/Documents/cafemat/node_modules/eslint-plugin-storybook/lib/rules/prefer-csf.js:18:44)
at /Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
at NodeEventGenerator.applySelectors (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
at NodeEventGenerator.enterNode (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/node-event-generator.js:336:14)
at CodePathAnalyzer.enterNode (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
at /Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/linter.js:960:32
at Array.forEach (<anonymous>)
error Command failed with exit code 2.
Also, if I have my useFirebase.ts file focused (in view) on VSCode and run yarn start I get the error:
Failed to compile
Cannot read property 'name' of undefined
Occurred while linting /Users/Reynaldo/Documents/cafemat/src/hooks/useFirebase.ts:13
This error occurred during the build time and cannot be dismissed.
Yet if I put in focus (into view) any other file on VSCode and run yarn start the project compiles and runs without problems.
Is this a weird bug or am I doing something wrong? Here are the files:
useFirebase.ts
import { useEffect, useState } from "react";
import { FirebaseApp, deleteApp, getApp, initializeApp } from "firebase/app";
import { appName, firebaseConfig } from "../config/firebaseConfig";
function useFirebase(): FirebaseApp | null {
const [firebaseApp, setFirebaseApp] = useState<FirebaseApp | null>(null);
useEffect(() => {
let app: FirebaseApp;
try {
app = getApp(appName);
}
catch (err) {
app = initializeApp(firebaseConfig, appName);
}
setFirebaseApp(app);
return () => {
deleteApp(app);
};
}, []);
return firebaseApp;
}
export default useFirebase;
package.json
{
"name": "xxxxxxx",
"version": "0.1.0",
"private": true,
"dependencies": {
"#reach/router": "1.3.4",
"firebase": "9.1.3",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-helmet-async": "1.1.2",
"react-scripts": "4.0.3",
"web-vitals": "1.0.1"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"format": "prettier --write 'src/**/*.ts{,x}'",
"lint": "tsc --noEmit && eslint src/**/*.ts{,x}",
"cypress:open": "cypress open",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"serve": "serve -s build"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"overrides": [
{
"files": [
"**/*.stories.*"
],
"rules": {
"import/no-anonymous-default-export": "off"
}
}
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#craco/craco": "^6.2.0",
"#storybook/addon-actions": "^6.3.2",
"#storybook/addon-essentials": "^6.3.2",
"#storybook/addon-links": "^6.3.2",
"#storybook/node-logger": "^6.3.2",
"#storybook/preset-create-react-app": "^3.1.7",
"#storybook/react": "^6.3.2",
"#tailwindcss/postcss7-compat": "^2.2.4",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"#types/jest": "^26.0.15",
"#types/node": "^12.0.0",
"#types/reach__router": "^1.3.9",
"#types/react": "^17.0.13",
"#types/react-dom": "^17.0.0",
"#types/react-helmet": "^6.1.2",
"#typescript-eslint/eslint-plugin": "^4.28.1",
"#typescript-eslint/parser": "^4.28.1",
"autoprefixer": "^9",
"babel-loader": "8.1.0",
"cypress": "^7.6.0",
"eslint": "^7.2.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-chai-friendly": "^0.7.1",
"eslint-plugin-cypress": "^2.11.3",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^1.7.0",
"eslint-plugin-storybook": "^0.1.1",
"postcss": "^7",
"postcss-cli": "^8.3.1",
"prettier": "^2.3.2",
"tailwindcss": "npm:#tailwindcss/postcss7-compat",
"typescript": "^4.1.2"
}
}
.eslintrc
{
"extends": [
"airbnb-typescript",
"airbnb/hooks",
"plugin:#typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended",
"plugin:cypress/recommended",
"plugin:chai-friendly/recommended"
],
"plugins": [
"react",
"#typescript-eslint",
"jest",
"cypress",
"chai-friendly",
"storybook"
],
"env": {
"browser": true,
"es6": true,
"jest": true,
"cypress/globals": true
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"linebreak-style": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"cypress/no-assigning-return-values": "error",
"cypress/no-unnecessary-waiting": "error",
"cypress/assertion-before-screenshot": "warn",
"cypress/no-force": "warn",
"cypress/no-async-tests": "error",
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": 2,
"storybook/prefer-csf": "error"
}
}
.eslintignore
# Temporary lint ignore because storybook example files
# generated files that go against specified ESLint rules.
src/stories
# ESLinting error taken off by ignoring config files
# https://stackoverflow.com/questions/58510287/parseroptions-project-has-been-set-for-typescript-eslint-parser/64488474#64488474
tailwind.config.js
postcss.config.js
craco.config.js
Ok so I solved the problem. For some reason the prefer-csf rule of eslint-plugin-storybook causes this error. Once I commented out "storybook/prefer-csf": "error" from the .eslintrc the yarn lint command runs without problems. If anyone has a clue as to why this solves the error it would be greatly appreciated if you could explain. Thanks! :D

Storybook Viewport Addon: Custom Viewports Do Not Build (react)

I built an app using create-react-app. I create custom viewport types to add to my storybook. When I use yarn start everything builds fine and works. But when I build the app the viewports that I globally defined my preview.js file are not loading on the build. It is still the defaults. And for the life of me I can't figure out why. As far as I can tell I set it up the way the documentation explains.
This is my preview.js file
import { configure, addDecorator, addParameters } from '#storybook/react';
import { DocsPage, DocsContainer } from '#storybook/addon-docs/blocks';
import { withA11y } from '#storybook/addon-a11y';
import { GlobalStyle } from '../src/styles/global-styles';
const loaderFn = () => {
const allExports = [];
const styles = require.context('../src/styles', true, /\.stories\.(js|mdx)$/);
const req = require.context('../src/components', true, /\.stories\.(js|mdx)$/);
addDecorator(withA11y, GlobalStyle);
styles.keys().forEach(fname => allExports.push(styles(fname)));
req.keys().forEach(fname => allExports.push(req(fname)));
return allExports;
};
const customViewports = {
phoneSmall: {
name: 'Phone (320px min width)',
styles: {
width: '320px',
height: '667px',
},
},
tabletSmall: {
name: 'Tablet Small & Portrait (600px min width)',
styles: {
width: '600px',
height: '801px',
},
},
tabletLarge: {
name: 'Tablet Large & Landscape (960px min width)',
styles: {
width: '960px',
height: '768px',
},
},
desktop: {
name: 'Desktop (1200px min width)',
styles: {
width: '1200px',
height: '1024px',
},
},
};
configure(loaderFn, module);
addParameters({
docs: {
container: DocsContainer,
page: DocsPage,
},
viewport: { viewports: customViewports },
});
My main.js file
module.exports = {
stories: ['../src/**/*.stories.(js|mdx)'],
addons: [
'#storybook/preset-create-react-app',
'#storybook/addon-knobs/',
'#storybook/addon-actions',
'#storybook/addon-links',
'#storybook/addon-notes',
'#storybook/addon-storysource',
'#storybook/addon-a11y',
'#storybook/addon-docs',
'#storybook/addon-viewport',
]
}
Package.json
{
"name": "tamman-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"#storybook/addon-a11y": "^5.3.17",
"#storybook/addon-actions": "^5.3.17",
"#storybook/addon-docs": "^5.3.17",
"#storybook/addon-knobs": "^5.3.17",
"#storybook/addon-links": "^5.3.17",
"#storybook/addon-notes": "^5.3.17",
"#storybook/addon-storyshots-puppeteer": "^5.3.17",
"#storybook/addon-storysource": "^5.3.17",
"#storybook/addon-viewport": "^5.3.17",
"#storybook/addons": "^5.3.17",
"#storybook/preset-create-react-app": "^2.1.0",
"#storybook/react": "^5.3.17",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"autoprefixer": "^9.7.5",
"camel-case": "^4.1.1",
"core-js": "^3.6.4",
"del": "^5.1.0",
"fs": "^0.0.1-security",
"node-sass": "^4.13.1",
"pascal-case": "^3.1.1",
"path": "^0.12.7",
"prop-types": "^15.7.2",
"puppeteer": "^2.1.1",
"react": "^16.12.0",
"react-dom": "^16.13.1",
"react-scripts": "^3.4.1",
"styled-components": "^5.0.1",
"xml2js": "^0.4.23"
},
"scripts": {
"start": "node ./src/components/atoms/Icon/utils/generate-icons.js && react-scripts start",
"build-page": "node ./src/components/atoms/Icon/utils/generate-icons.js && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 9009 -s public",
"build": "yarn build-page && build-storybook -o build/storybook"
},
"eslintConfig": {
"extends": "react-app"
},
"homepage": ".",
"browserslist": [
"since 2010"
],
"devDependencies": {
"babel-loader": "^8.1.0",
"react-is": "^16.12.0"
}
}
Seems to be working fine. Try registering the viewport add-on
// main.js
module.exports = {
...
addons: [
...
'#storybook/addon-viewport/register',
],
]
}
Like the docs suggest.

Resources