Creating a new project with npx dts-cli create test3, choosing the react-with-storybook preset and then running npm run build will give you this error:
(typescript) RollupError: src/index.tsx:1:8 - error TS1259: Module '"C:/Users/_/repos/test3/node_modules/@types/react/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
1 import React, { FC, HTMLAttributes, ReactChild } from 'react';
~~~~~
node_modules/@types/react/index.d.ts:47:1
47 export = React;
~~~~~~~~~~~~~~~
This module is declared with 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
at error (C:\Users\_\repos\test3\node_modules\rollup\dist\shared\rollup.js:353:30)
at Object.error (C:\Users\_\repos\test3\node_modules\rollup\dist\shared\rollup.js:1721:20)
at RollupContext.error (C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:1452:26)
at C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:27634:26
at Array.forEach (<anonymous>)
at printDiagnostics (C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:27610:17)
at typecheckFile (C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:27966:9)
at Object.<anonymous> (C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:28103:21)
at Generator.next (<anonymous>)
at C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:63:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:59:12)
at Object.transform (C:\Users\_\repos\test3\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:28084:20)
at C:\Users\_\repos\test3\node_modules\rollup\dist\shared\rollup.js:1914:40
Expected behavior
A new project should build correctly without errors
Suggested solution(s)
As the error hints towards, add "allowSyntheticDefaultImports": true in the tsconfig.json file
Current Behavior
Creating a new project with
npx dts-cli create test3
, choosing thereact-with-storybook
preset and then runningnpm run build
will give you this error:Expected behavior
A new project should build correctly without errors
Suggested solution(s)
As the error hints towards, add
"allowSyntheticDefaultImports": true
in thetsconfig.json
fileAdditional context
None
Your environment