🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Troubleshooting a dev error with npm run dev command in a NextJs project.

12 replies
Last updated: Apr 24, 2024
Hi everyone, I've been troubleshooting this dev error for a while so finally asking the larger community. Error shows up on
npm run dev
command:

Import trace for requested module:
./node_modules/<@UFY5PJF3M>/client/dist/index.browser.js
./sanity/sanity.client.ts
./sanity/sanity.query.ts
./app/(site)/projects/[project]/page.tsx
 ⨯ ./node_modules/<@UFY5PJF3M>/client/dist/index.browser.js
Attempted import error: 'retry' is not exported from 'get-it/middleware' (imported as 'retry').
And then the attached image is what it looks like.

I'm not too sure where to start on this kind of thing so any advice would be super duper helpful. Happy to provide any other info that's needed. Thanks in advance!
Apr 22, 2024, 4:38 PM
👋 Can you share some more details about your build? What version of the Studio are you running? Are you embedding it in an app? If so, can you share that code?
Apr 22, 2024, 6:08 PM
I just started having this same error after updating my packages
user M
. It's a monorepo, but it's breaking my nextjs app...I just saw the error and started investigating, but here is some of the pipeline logs in case it helps:
Apr 23, 2024, 12:31 PM
Greetings. I've been trying some ideas on another request, and have a possble solution here , which might help.

Can any of you code it and see?
Actually, this doesn't look right either, according to a couple of IDEs.

What NextJs framework example are you guys building from?
Apr 23, 2024, 3:50 PM
This is an actual production project from a client of the company I work for...
Apr 23, 2024, 5:40 PM
meaning you don't know what it might have been based upon? Unfortunately that seems to be the situation for another person running into this.
I've just looked into what might have changed in get-it, and there has been a quite recent update.
-- nothing about that package export signature has changed in a long time, though, so it's not that
-- however, Vite versions have been steadily upgrading
-- the actual import line should be ok, just importing from get-it/middleware

There's a suggestion that 'clearing' Vite's cache might help, forcing it to re-bundle -- and it's in a linking or 'bundling' level that this problem seems to show. So could you try this:

• what you want is to run npm dev or build with an additional pair of arguments:: -- --force
• so if you do it directly, this should work:
npm run dev/build -- --force
• or if you are using a script in package.json to run it, alter the script to look the same
Hope that's clear, and looks easy to try -- thanks, LC :)
Apr 23, 2024, 5:46 PM
p.s. a reasonably safe alternative to the -- --force build might be to remove your node_modules folder/s, then do
npm install
from the appropriate places.

Not npm update.
But then following the npm install with your npm dev/build sequence as usual.

This should just install package versions as you have, from the package-lock.json files you haven't touched, but with the Vite cache eliminated as it's in node_modules, giving Vite the chance to re-bundle properly.


@User, just as interested if you have a GitHub example your problem development is based on, thanks!
Apr 23, 2024, 7:02 PM
Thank you
user M
and thank you
user Q
!
User, I've been following along all day and trying to find a good way to catch you up on all the ... failed
🙃 attempts. Really appreciate the help so far!
We can start with Github here:

https://github.com/taliacotton/almost-sanity
Versions:
"@sanity/cli": "3.38.0",

Some other commands that return errors that might shine a light on something?


npm run build
and
npm run build --force
both return:
> site@0.1.0 build
> next build

Failed to compile.

./node_modules/@sanity/client/dist/index.browser.js
Module not found: Package path ./middleware/browser is not exported from package /Users/taliacotton/Documents/GitHub/almost-sanity/node_modules/get-it (see exports field in /Users/taliacotton/Documents/GitHub/almost-sanity/node_modules/get-it/package.json)

<https://nextjs.org/docs/messages/module-not-found>

Import trace for requested module:
./sanity/sanity.client.ts
./sanity/sanity.query.ts
./app/(site)/profile/page.tsx


> Build failed because of webpack errors
   Creating an optimized production build  .%     
Both
npm install
and
npm install --legacy-peer-deps
return:
npm ERR! Invalid Version: 6.1

npm ERR! A complete log of this run can be found in: /Users/taliacotton/.npm/_logs/2024-04-23T19_52_20_717Z-debug-0.log
Happy to provide any and all more info if needed! Definitely lost on all of the above, and really appreciate the help
🙏
Apr 23, 2024, 7:57 PM
Thanks, User and that looks like a good test case for sure :)
I'll have to be away, but will try to have a look later today if possible.

You take care,
User
Apr 23, 2024, 8:00 PM
Ok, User, I've gotten your site to run, in both dev and build/start -- quite amazed at design when first came up :).
The problem: in summary, it appears that Sanity's moved on so that Next 14, rather than present 13, is needed to run your code. Fortunately, this seems easy enough to provide, so I've worked that out I think as a practical approach to this 'retry' bundling problem..

Let's look at what I had to do:
• first, the problem had nothing to do with "use client" needs earlier proposed
• that's because this is a NextJs arrangement where all happens on the server; there are not client components.
• you've been running a 7-month old version of NextJs, and that has apparently fallen out of compatibility with Sanity.
• I tried a number of alternatives of backing up Sanity items to earlier versions, but had no success -- too many peer dependencies keeping something problematic in play I suspect
• What worked was to leave most Sanity items alone, and instead to upgrade to next@latest and next-sanity@latest
• With these, and some other adjustments I had to do first, your site functions, both web pages and the Studio coming up -- you'll have to test that with your login, but I suspect it will be healthy.
Ok, what do you do?
• When I cloned your repo, the package-lock.json was corrupted. I traced that to the use of npm-force-resolutions, which doesn't work anyway, since npm versions now intercept the resolution problem and fail installs, before it can act
• So, I removed the items from your package.json which activate it, and you will from now on add the --legacy-peer-deps flag to any npm operations. Example:
npm install --legacy-peer-deps
• (this is to work around the ongoing problems with styled-components versions, until those are finally matched)
• You need to remove
package-lock.json
and the
node_modules
folder entirely from your project, before proceeding• You can then make all the changes in versions and accomplish the removals nicely, by updating your package.json to match the one I've attached.
• Then do your
npm install --legacy-peer-deps
, to install all items fresh in the new specified versionsAt this point, you should be able to npm run dev, or npm run build/npm start to see your site. Test the /edit for the Studio also, to assure that is in good condition now.

All I could test works nicely in the browser, but has some problems which show where you are running dev, or equivalently on the server.

Most at least of these are about images being improperly specified -- if you use one of the errored 400 paths in a browser, Sanity's server will tell you what's wrong, that 'Parameter "w" must be a positive number'. You can work this out, and any other errors once those are cleared, probably from one spot in your code.

User, good to hear back from you that you got this working, before you chase the minor errors, and whether the Studio is healthy, so that everyone can see how things work out this way.

Hope indeed it does work for you :)

User
Apr 24, 2024, 4:39 AM
User! You ANGEL! This did the trick. Where can I buy you a coffee? Really, really appreciate it. 🥲
Apr 24, 2024, 1:57 PM
Sorry for the delay in the response,
user Q
. I actually work on that project and was trying to help the other developer with that issue. Due to the timeline we had to pause the update but we plan to be back at this next week. Thanks in advance for the detailed steps...really appreciate it and I'll let you know how it goes once I try it.
Also, I'm glad it solved User's problem already
🙌
Apr 24, 2024, 4:32 PM
User, that's great to hear :) Coffee is ok, you're just welcome...!
LC, understand, and hope this gets your project also under way, once you can return to it.

Best to both,
User
Apr 24, 2024, 8:11 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?