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] Snowpack 3.1.1 fails with react-router-dom - incorrect namespace import #2933

Closed
4 tasks done
BPScott opened this issue Mar 20, 2021 · 1 comment
Closed
4 tasks done

Comments

@BPScott
Copy link
Collaborator

BPScott commented Mar 20, 2021

Bug Report Quick Checklist

  • I am on the latest version of Snowpack & all plugins.
  • I use package manager npm (Fill in: npm, yarn, pnpm, etc).
  • I run Snowpack on OS macos (Fill in: Windows, Mac, Linux, etc).
  • I run Snowpack on Node.js v12+

Describe the bug

Using react-router-dom fails in Snowpack 3.1.1 when used in conjunction with
React 16.14.0. This previously worked in Snowpack 3.0.13.

Attempting to use the router results in the following error:

Uncaught TypeError: checkPropTypes is not a function
    at validatePropTypes (react.v16.14.0.js:1729)

I suspect this is because react's compiled output expects checkPropTypes to be a
function however it is imported using a namespace definition which is not callable.

// At the top of /_snowpack/pkg/react.v16.14.0.js
import * as checkPropTypes from '/_snowpack/pkg/prop-types.checkPropTypes.v15.7.2.js';

The issue goes away if I either:

  • Use snowpack 3.0.13 and react 16.14.0 (downgrade snowpack, keep react version)
  • Use snowpack 3.1.1 and react >=17.0.0 (keep snowpack version, update react)

To Reproduce

Reproduction repository is here

  • clone repository and go into the react-router-prop-types folder
  • npm install && npm start
  • See error as described above

General steps

  • Use snowpack 3.1.1
  • Use react 16.14.0
  • Use react-router-dom 5.2.0
  • Add an importimport { BrowserRouter as Router } from "react-router-dom"; in App component
  • Add the Router somewhere in your App component <Router></Router>

Expected behavior

Page to render, no errors

@FredKSchott
Copy link
Owner

@BPScott thanks for filing. Funny enough, I tracked this down to the snippet of code that we'd originally talked through related to ESM vs. CJS detection. More details here, including the fix to add back that check: #2934

I'll get this out tonight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants