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

[Bug][v6]: StaticRouter can't import as documented #8353

Closed
duhdugg opened this issue Nov 18, 2021 · 4 comments
Closed

[Bug][v6]: StaticRouter can't import as documented #8353

duhdugg opened this issue Nov 18, 2021 · 4 comments
Labels

Comments

@duhdugg
Copy link

duhdugg commented Nov 18, 2021

What version of React Router are you using?

6.0.2

Steps to Reproduce

npx create-react-app test-app
cd test-app
yarn add react-router-dom@6.0.2
// src/App.js
import { StaticRouter } from 'react-router-dom/server'
yarn build

Expected Behavior

StaticRouter should import without error, as documented here: https://reactrouter.com/docs/en/v6/upgrading/v5#get-staticrouter-from-react-router-domserver

Actual Behavior

Error:

Failed to compile.

./node_modules/react-router-dom/server.mjs
Can't import the named export 'Action' from non EcmaScript module (only default export is available)
@duhdugg duhdugg added the bug label Nov 18, 2021
@timdorr
Copy link
Member

timdorr commented Nov 18, 2021

The file definitely exists, but your tooling is pulling in the mjs version instead of the js version. The history library it's importing from doesn't have those as exports because they are just types.

I'll see if we can fix this on our end. In the meantime, you might try switching to importing from react-router-dom/server.js, if that will override where it imports from.

@timdorr
Copy link
Member

timdorr commented Nov 18, 2021

Found a fix for you: formatjs/formatjs#1395 (comment)

I double-checked and we do actually export Action, as it's an enum and has real value in non-TS code. The problem here is really more on the build tooling side. We can see about exporting mjs files in history, but there's nothing we've done strictly "wrong" here.

@timdorr timdorr closed this as completed Nov 18, 2021
@paul-mesnilgrente
Copy link

That's the same issue I had on: #8221

@duhdugg
Copy link
Author

duhdugg commented Feb 16, 2022

Importing from react-router-dom/server.js (explicit .js extension) as suggested fixed it for me back when I originally had this problem.

I just checked again by dropping the .js from the import in my project, and I'm not having the same problem as before. I try to keep the dependencies in my project updated as much as possible, so I'm using react-router@6.2.1 right now. yarn list also shows history@5.2.0, although I admit I am unfamiliar with how that package is related (just saw it was mentioned in #8221).

duhdugg added a commit to duhdugg/preaction-cms that referenced this issue Feb 16, 2022
background: remix-run/react-router#8353 (comment)

`.js` extension seems to be no longer needed

This also has the added benefit of
reducing the bundle size by about 1.65kB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants