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

valtio 1.5.0 in Next.js #410

Closed
oleksyoleksy opened this issue Mar 31, 2022 · 7 comments · Fixed by #411
Closed

valtio 1.5.0 in Next.js #410

oleksyoleksy opened this issue Mar 31, 2022 · 7 comments · Fixed by #411

Comments

@oleksyoleksy
Copy link

After yarn create next-app . && yarn add valtio,

when valtio is imported to ~/pages/index.js with import { proxy, useSnapshot } from 'valtio',

there is an error:
error - Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '~/node_modules/use-sync-external-store/shim' is not supported resolving ES modules imported from ~/node_modules/valtio/esm/index.mjs Did you mean to import ~/node_modules/use-sync-external-store/shim/index.js?

Any idea how to fix it?

@dai-shi
Copy link
Member

dai-shi commented Mar 31, 2022

Thanks for reporting!
Ah, I forgot about it. It's reported in pmndrs/zustand#829 and I made a fix there.
Let's do the same here.

@dai-shi
Copy link
Member

dai-shi commented Mar 31, 2022

Can you try #411?
https://ci.codesandbox.io/status/pmndrs/valtio/pr/411
Please find "Local Install Instructions" in ☝️ .

@LefanTan
Copy link

LefanTan commented Apr 1, 2022

unfortunately, another error persist whenever I tried to create a proxy state:

error - Error: ENOTDIR: not a directory, stat '/Users/lefantan/Documents/CS/popin/node_modules/use-sync-external-store/shim/index.js/index.js'

Another behavior I noticed is, this error only appears whenever I directly load the page that creates the proxy. If I enter the page that creates the proxy from another page (that doesn't create any proxy), it works fine, that is until I refresh.

I was able to fix this by writing import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js instead of import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js/index.js in dist/esm/index.js and dist/esm/index.mjs

@deadcoder0904
Copy link

i have the same error & npm i pmndrs/valtio#fix/build/path-for-cjs isn't working even tho i do it every time as i have this answer bookmarked.

also, tried setting it in package.json like:

"valtio": "github:pmndrs/valtio#fix/build/path-for-cjs"

& then npm i but still ain't working. i get an error:

npm ERR! The git reference could not be found
npm ERR! command git --no-replace-objects checkout fix/build/path-for-cjs
npm ERR! error: pathspec 'fix/build/path-for-cjs' did not match any file(s) known to git

never had / in branch name but is there any other way to install it?

@dai-shi
Copy link
Member

dai-shi commented Apr 1, 2022

Thanks, guys. That was a silly mistake.
#411 is updated. Please try the new commit.

@sivadinesh1
Copy link

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '.../node_modules/use-sync-external-store/shim' is not supported resolving ES modules imported from /Users/sivadinesh/Documents/products/2022/greenpot/node_modules/valtio/esm/index.mjs
Did you mean to import use-sync-external-store/shim/index.js?
at new NodeError (node:internal/errors:371:5)
at finalizeResolution (node:internal/modules/esm/resolve:414:17)
at moduleResolve (node:internal/modules/esm/resolve:983:10)
at defaultResolve (node:internal/modules/esm/resolve:1080:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
at ModuleWrap. (node:internal/modules/esm/module_job:79:40)
at link (node:internal/modules/esm/module_job:78:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///Users/sivadinesh/Documents/products/2022/greenpot/node_modules/use-sync-external-store/shim'
}
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/sivadinesh/Documents/products/2022/greenpot/node_modules/use-sync-external-store/shim' is not supported resolving ES modules imported from /Users/sivadinesh/Documents/products/2022/greenpot/node_modules/valtio/esm/index.mjs
Did you mean to import use-sync-external-store/shim/index.js

@LefanTan
Copy link

LefanTan commented Apr 2, 2022

Thanks, guys. That was a silly mistake. #411 is updated. Please try the new commit.

This works, thanks for the quick fix.

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

Successfully merging a pull request may close this issue.

5 participants