Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support import JSX from JS file #571

Merged
merged 2 commits into from
Mar 2, 2020
Merged

Conversation

n3tr
Copy link
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 [email protected]: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.

@@ -527,6 +527,7 @@ function createConfig(options, entry, format, writeMeta) {
nodeResolve({
mainFields: ['module', 'jsnext', 'main'],
browser: options.target !== 'node',
extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],
Copy link
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
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
Collaborator

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 2, 2020

Build succeeded

@bors bors bot merged commit 6012f39 into developit:master Mar 2, 2020
@ForsakenHarmony
Copy link
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