Skip to content

Commit 6012f39

Browse files
bors[bot]n3tr
andauthored
Merge #571
571: Support import JSX from JS file r=ForsakenHarmony a=n3tr ## Changes - Support import JSX from JS file by adding JSX extension to `@rollup/plugin-node-resolve` plugin ## Background I have experience an error when importing `.jsx file` from `.js` file like ``` index.js -> A.jsx ``` will cause an error ``` Could not resolve './A' from src/index.js ``` However, Importing `.jsx` file from TypeScript file (`.ts`) file is seems working fine except the the import is chaining more than 3 levels depth. ```sh index.ts -> A.jsx # This is fine index.ts -> A.jsx -> B.jsx # This is fine index.ts -> A.jsx -> B.jsx -> C.jsx # Error: Could not resolve './C' from src/jsx-components/B.jsx ``` To reproduce the issue ```sh git clone -b import-jsx-error --single-branch git@github.com:n3tr/microbundle-example.git cd microbundle-example yarn yarn build --jsx React.createElement ./src/index.js # or yarn build --jsx React.createElement ./src/index.ts ``` --- I'm not really sure what is the root cause of the error, by adding extensions seems to fix the problem. Co-authored-by: Jirat Ki <saakyz@gmail.com>
2 parents 8cc0d7b + 875558b commit 6012f39

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ function createConfig(options, entry, format, writeMeta) {
527527
nodeResolve({
528528
mainFields: ['module', 'jsnext', 'main'],
529529
browser: options.target !== 'node',
530+
// defaults + .jsx
531+
extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],
530532
}),
531533
commonjs({
532534
// use a regex to make sure to include eventual hoisted packages

0 commit comments

Comments
 (0)