Compilation for Vite.js
See original GitHub issueHello,
I was messing around with Vite.js (with TypeScript & React) and tried to use Recoil, but importing the lib seems broken with Rollup or Vite.
I got a Uncaught SyntaxError: import not found: atom
in console when I try to use atom.
I’ve just modified the default page by adding to the default Vite/React/TS template (yarn create vite-app --template react-ts
)
import { atom } from 'recoil'
// [...]
const state = atom({
key: 'state',
default: ''
})
Here is a demo repo : https://github.com/Rykian/vitejs-test-recoil
You just have to run a yarn install
& yarn dev
and go to http://localhost:3000 to see the error.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Features | Vite
Rewrite the imports to valid URLs like /node_modules/.vite/deps/my-dep.js?v=f3sf2ebd so that the browser can import them properly. Dependencies are Strongly ...
Read more >Building for Production - Vite
Check out the Deploying a Static Site for guides about popular services. Browser Compatibility #. The production bundle assumes support for modern JavaScript....
Read more >Configuring Vite
Configuring Vite #. When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project...
Read more >Build Options - Vite
This option allows users to set a different browser target for CSS minification from the one used for JavaScript transpilation. It should only...
Read more >Why Vite
Vite aims to address these issues by leveraging new advancements in the ... and the rise of JavaScript tools written in compile-to-native languages....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree with @JeremyRH. With next release Recoil will come with a ES format build and should thus can work with Vite. Unfortunately I haven’t got time to play with Vite myself (although have been watching Evan You bragging about it for a while). It’s much appreciated if you can try build latest master branch and test with Vite. Otherwise, let’s wait for next release and see if it works.
I’ll investigate and fix this issue if it’s still broken on next release.
For dev builds, Vite uses @rollup/plugin-commonjs which attempts to convert CommonJS to ES modules.
In this case, Vite uses @rollup/plugin-commonjs to transform Recoil’s index.js file. That file does not have “named exports” in the CommonJS style:
exports.atom = ...
. This means named exports in the ES module format are not generated.Changes are coming that could fix this issue. I’m not familiar enough with Vite to know if it takes advantage of packages that output ES modules.