uppy: Uppy throws with latest create-react-app (react-scripts 5), Uncaught TypeError: nanoid is not a function
To reproduce the error: https://github.com/waveiron/uppy_example_1 It was created using create-react-app, only App.tsx and package.json dependencies are changed
You can follow the steps to reproduce the error:
npx create-react-app --template typescript my_app
package.json
// ...
"dependencies": {
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.0.3",
"@types/node": "^16.11.14",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"@uppy/core": "^2.1.4",
"@uppy/react": "^2.1.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"typescript": "^4.5.4",
"web-vitals": "^2.1.2"
},
// ...
App.tsx
import Uppy from '@uppy/core';
import { Dashboard, useUppy } from '@uppy/react';
import React from 'react';
import './App.css';
function App() {
const uppy = useUppy(() => {
return new Uppy();
});
return (
<Dashboard uppy={uppy}/>
);
}
export default App;
npm start

About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (9 by maintainers)
Commits related to this issue
- Revert to using the standard nanoid to avoid https://github.com/transloadit/uppy/issues/3376. Please note this may break React Native compatibility. — committed to SendHeirloom/uppy by zackbloom 3 years ago
- Working around https://github.com/transloadit/uppy/issues/3376 via patch-package — committed to hygieia-saas/hygieia-webapp by manuelkiessling 2 years ago
- fix: revert to react-scripts 4.0.3 (for uppy) See https://github.com/transloadit/uppy/issues/3376 BREAKING CHANGES — committed to graasp/graasp-app-sticky-notes by swouf 2 years ago
Do we have any progress on this issue
Thanks @zackbloom. In response to https://github.com/transloadit/uppy/issues/3376#issuecomment-1000400488 I used customize-cra to add a new webpack rule without ejecting.
I added the following in
config-overrides.jsFor anyone trying to understand the misconfiguration, it seems adding
cjsto the list of extensions which should be processed by babel in areas like this solves it.A short term solution is for anyone suffering this issue to eject their app from CRA, and make that change.
@DavidDuwaer I used this customization on my project and this is working well. You can find it here: https://github.com/oxyno-zeta/s3-proxy-interfaces in the dashboard folder for example. The configuration provided needs to have ‘react-app-rewired’ installed and configured in the package.json (replacing the cra commands).
Hope it will work for you too !
PS: for the story I reverted my eject for that customization 😉 Thanks @duanecilliers
I have tried all suggested ways but it doesn’t return any errorless result. It returns same error that is nanoid is not a function
for those who encounter the same issue: https://github.com/facebook/create-react-app/pull/12021
Still error on react-scripts 5.0.0
Hallo, referring to @zackbloom solution about replacing const { nanoid } = require(‘nanoid/non-secure’) with const { nanoid } = require(‘nanoid’), how can i apply this solutions in my node_modules in React project? i am experiencing this issue and it is a blocking issue for me. Thanks a lot
Also need a fix on this issue. It’s breaking, so I guess the only option is to not use <Dashboard/>. Ejecting CRA is never an option; switching to something other than CRA is a similar way too large thing to do for a single library and the customize-cra fix in the comment above doesn’t work for me (on the dev server, is what I’ve tested. Anyone who did get that to work?).
https://unpkg.com/nanoid@3.1.30/non-secure/index.cjs
I don’t think using
.jsextension would help.I’m not sure, I think using the non-secure implementation is beneficial for us (we don’t use
nanoidfor anything related to security) as it decreases the bundle size and works natively in more places. The issue here is with create-react-app specifically, I’m not sure it’s worth making Uppy bigger in bundle size for everyone because of a bug in one build tool. Has the bug been reported to create-react-app? If there’s a fix incoming, it’s definitely not worth reverting.I’ve been struggling with this issue for 2 days, someone please help 😭😭