-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Cannot use import statement outside a module #5464
Comments
Hello! This definitely seems like a bug, react router is not transpiled, so the feature detection doesn't work here. I'm not sure why though. I'll be able to look at this on Friday! |
Ah, interesting, it seems like our transpiler is tripping over |
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed. |
I started seeing this today, too (with Grommet: https://github.com/grommet/grommet). It wasn't happening yesterday. Reproduction sandbox: https://codesandbox.io/s/import-bug-reproduction-v6rct?file=/src/App.tsx |
@jsejcksn thanks for reporting gonna look into this right away, we changed some logic yesterday that should eliminate some extra compilation but apparently we haven't handled all the edge cases yet |
I saw where each of the components uses a conditional check for NODE_ENV to see if it's dev or production in order to load them in some kind of wrapped documentation function. Is there a non-runtime way (e.g. some kind of package.json config or alt import map) to use different modules during bundling based on that env value? |
There's a couple ways, the runtime way would probably be using an In pkg#json there is the For now require or a regular import is probably the best as everything around ESModules is still very fresh and both tooling and specifications are slowly catching up. Just didn't really think about this edge case when I changed the logic |
Yeah, I encountered issues using top-level await: I suspected that it's an issue with React (since it's supported by Node >=14.8), but I couldn't find any documentation to support or contradict that idea.
Thanks for sharing this—it's exactly what I was looking for. I was aware of conditional exports, but custom conditions weren't implemented yet the last time I looked at the docs. |
Cannot reproduce the original issue anymore, does it still happen? |
why can't one use if I open Google Chrome and type something pointless like |
It looks like a fix for this was merged a few hours ago as discussed in this issue. Please let us know if you're still experiencing any issues. |
#8435 <-- this still doesn't work |
🐛 bug report
Preflight Checklist
Contributing Guidelines
for this project.
Code of Conduct
that this project adheres to.
to file, without success.
Description of the problem
When trying to transpile to project, codesandbox throws an error
Cannot use import statement outside a module
, which points to the following importimport { BrowserRouter, Route, Switch, Redirect } from "react-router-dom";
How has this issue affected you? What are you trying to accomplish?
I am trying to run the project.
To Reproduce
Go to provided sandbox link.
Link to sandbox: link (optional)
https://codesandbox.io/s/magical-worker-r3ikv
Your Environment
The text was updated successfully, but these errors were encountered: