Skip to content

Support import JSX from JS file#571

Merged
bors[bot] merged 2 commits intodevelopit:masterfrom
n3tr:node-resolve-extensions
Mar 2, 2020
Merged

Support import JSX from JS file#571
bors[bot] merged 2 commits intodevelopit:masterfrom
n3tr:node-resolve-extensions

Conversation

@n3tr
Copy link
Copy Markdown
Contributor

@n3tr n3tr commented Feb 28, 2020

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.

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

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.

Comment thread src/index.js
nodeResolve({
mainFields: ['module', 'jsnext', 'main'],
browser: options.target !== 'node',
extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just kinda wondering if there could be problems with typescript, probably not because everything in node modules should already be compiled

Copy link
Copy Markdown
Contributor Author

@n3tr n3tr Mar 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just add jsx to the list of the default values, nothing should be different for TypeScript.
😄

@ForsakenHarmony
Copy link
Copy Markdown
Collaborator

bors r+

@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Mar 2, 2020

Build succeeded

@bors bors Bot merged commit 6012f39 into developit:master Mar 2, 2020
@ForsakenHarmony
Copy link
Copy Markdown
Collaborator

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants