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

SyntaxError: Cannot use import statement outside a module #31

Closed
joseph1125 opened this issue Dec 24, 2020 · 4 comments · Fixed by #33
Closed

SyntaxError: Cannot use import statement outside a module #31

joseph1125 opened this issue Dec 24, 2020 · 4 comments · Fixed by #33

Comments

@joseph1125
Copy link

When working with nextjs, it is founded that the server returns error as this syntax error pops out

import{useState as t,useEffect as o}from"react";import r from"copy-to-clipboard";export default function(c,e){const[i,n]=t(!1),u=e&&e.successDuration;return o(()=>{if(i&&u){const t=setTimeout(()=>{n(!1)},u);return()=>{clearTimeout(t)}}},[i,u]),[i,()=>{const t=r(c);n(t)}]}
^^^^^^

SyntaxError: Cannot use import statement outside a module
@danoc
Copy link
Owner

danoc commented Dec 24, 2020

Thanks for the issue, @joseph1125.

I think I know what the problem is. I'll take a pass at fixing it tomorrow. In the meantime, try version v1.0.2. I don't think it'll have the same problem.

@joseph1125
Copy link
Author

Thanks for the quick response, confirmed that v1.0.2 doesnt have this issue

@danoc
Copy link
Owner

danoc commented Dec 29, 2020

Hi! Just released 1.0.7 which includes a fix.

The issue was caused by the exports field in the package.json which is used for modern JavaScript. I'm not sure why it wasn't working, but I made #35 to track that.

@joseph1125
Copy link
Author

joseph1125 commented Dec 29, 2020 via email

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.

2 participants