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

Import fails #237

Closed
msabramo opened this issue Aug 4, 2021 · 14 comments · Fixed by #238
Closed

Import fails #237

msabramo opened this issue Aug 4, 2021 · 14 comments · Fixed by #238
Labels

Comments

@msabramo
Copy link
Contributor

msabramo commented Aug 4, 2021

I did:

npm install next-usequerystate

and then added to my code:

import { useQueryState } from 'next-usequerystate'

I got this error:

Failed to compile

./node_modules/next-usequerystate/dist/esm/index.js
Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> export * from './defs';
| export * from './useQueryState';
| export * from './useQueryStates'

Screen Shot 2021-08-04 at 1 13 06 PM

@franky47
Copy link
Member

franky47 commented Aug 5, 2021

Could you tell me more about your setup (transpiler, bundler, general processing of source files into final artifacts, use of ES modules, TypeScript, Babel, etc..) ?

@franky47 franky47 added the help wanted Extra attention is needed label Aug 5, 2021
@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

This happens with an app create with use-next-app, using the next-learn-starter:

npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn-starter/tree/master/learn-starter"

@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

It's not specific to next-learn-starter. I was able to reproduce it with an app created by:

npx create-next-app nextapp --use-npm

@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

I didn't think it would matter, but for the sake of completeness, it also still happens without the --use-npm flag:

npx create-next-app nextapp

@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

$ npm list
[email protected] /private/tmp/nextapp
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

This config seems to be using webpack5, in case that matters. I saw this when running npm run dev:

info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5

@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

Ah, interesting. I followed the link in the above message about webpack5 and that lead me to try putting:

webpack5: false

in next.config.js and then it seemed to work!

Note however that this is not a long-term solution as the above link says:

In Next.js 11 webpack 5 was enabled by default for all applications. You can still opt-out and use webpack 4 to help with backwards compatibility using webpack5: false in next.config.js
In the next major version webpack 4 support will be removed.

@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

Possibly of interest?

webpack/webpack#12598

msabramo added a commit to msabramo/next-usequerystate that referenced this issue Aug 6, 2021
@msabramo
Copy link
Contributor Author

msabramo commented Aug 6, 2021

#238 seems like it might fix this. Hopefully it doesn't have any bad side-effects.

@bogdansoare
Copy link

any news on this?

franky47 added a commit to msabramo/next-usequerystate that referenced this issue Sep 7, 2021
franky47 pushed a commit that referenced this issue Sep 7, 2021
@github-actions
Copy link

github-actions bot commented Sep 7, 2021

🎉 This issue has been resolved in version 1.4.0-beta.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47
Copy link
Member

franky47 commented Sep 7, 2021

@msabramo & @bogdansoare, let me know if 1.4.0-beta.5 works for you. I'm still waiting on a TS types bugfix from Next.js to bump a security PR and I'll look into crafting a proper release.

@msabramo
Copy link
Contributor Author

Yep I'm using 1.4.0-beta.5 and it's working well for me.

$ npm list next-usequerystate
[email protected] /Users/abramowi/dev/adobe/sensei/next-stock-prototype
└── [email protected]

Thank you!

@github-actions
Copy link

🎉 This issue has been resolved in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants