json-diff-kit
json-diff-kit copied to clipboard
fix import react error in some cases
Fixes #12.
Based on below resources, I changed "jsx": "react-jsx"
in tsconfig.json. It allows proper jsx compilation without import React from 'react'
.
https://stackoverflow.com/questions/64656055/react-refers-to-a-umd-global-but-the-current-file-is-a-module/65539274#65539274
https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#jsx-factories
I think it's okay to change the createElement
to _jsx
, but here are two things we should consider:
- We should modify the version of
react
andreact-dom
inpeerDependencies
. According to the article in React blog, the minimum version below 17 and support_jsx
call is16.14.0
, but currently it's^16.0.0
in this repo. - ~~It's better to have a file
tsconfig.dev.json
with"jsx": "react-jsxdev"
option.~~ This library uses ESBuild to compile, maybe you should changerollup.config.js
andesbuild.mjs
instead oftsconfig.json
.
Also, I'm curious why this will fix the "Cannot use import statement outside a module" issue. The compiled files are still in ESM, if your project doesn't use ESM and there's no transpiler (e.g. Webpack), you'll still get this error.
Maybe json-diff-kit
should provide CJS dist as well since ESM is not widely used as I expected...
I'd definitely love it if this had a CommonJS distribution; I'm currently struggling to get this to import using babel in a CommonJS-based project.
I'd definitely love it if this had a CommonJS distribution; I'm currently struggling to get this to import using babel in a CommonJS-based project.
CJS is on the way, but there're some issues to solve. A new version with CJS support will be released once I finish my company work (in a day or two I think).
For what it's worth, I forked your main branch and published what you have to a private package repository, and the CommonJS export is working great. Looking forward to when it's published.
Quality Gate passed
Issues
1 New issue
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code