question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compilation for Vite.js

See original GitHub issue

Hello, 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
mondaychencommented, Aug 4, 2020

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.

2reactions
JeremyRHcommented, Aug 4, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found