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 #383

Closed
MatheusRyuki opened this issue Jul 16, 2020 · 12 comments
Closed

SyntaxError: Cannot use import statement outside a module #383

MatheusRyuki opened this issue Jul 16, 2020 · 12 comments

Comments

@MatheusRyuki
Copy link

The react-plugin keep getting the error at Nextjs. (This is a SSR).

image

The dependencies:
"dependencies": {
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"animejs": "^3.2.0",
"axios": "^0.19.2",
"final-form": "^4.20.1",
"mui-rff": "^2.1.15",
"next": "^9.4.4",
"notistack": "^0.9.17",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-final-form": "^6.5.1",
"react-imask": "^6.0.5",
"react-swipeable-views": "^0.13.9",
"snyk": "^1.362.0",
"styled-components": "^5.1.1",
"yup": "^0.29.1"
},
"devDependencies": {
"@types/animejs": "^3.1.1",
"@types/node": "^14.0.23",
"@types/react": "^16.9.43",
"@types/react-swipeable-views": "^0.13.0",
"@types/styled-components": "^5.1.1",
"@types/yup": "^0.29.3",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"babel-plugin-styled-components": "^1.10.7",
"cz-conventional-changelog": "3.2.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"prettier": "^2.0.5",
"typescript": "^3.9.6"
},

@aryehb
Copy link

aryehb commented Jul 26, 2020

See #322.

@MatheusRyuki
Copy link
Author

@aryehb I've read this issue, however, it doesn't help at all, because this is on Jest, what I'm trying to do is run on Nextjs (ssr).

@aryehb
Copy link

aryehb commented Jul 27, 2020

Look at my comment here.

I looked through the Next.js source, but I can't tell if the default config excludes node_modules. You might have to use a custom Webpack config to set this.

@mircoservices
Copy link

mircoservices commented Aug 1, 2020

@MatheusRyuki had the same issue in SSR, also couldn't get babel to work well with the esm import.

So I removed the forced esm import: mircoservices@653bfc3

Published as quick-fix:
https://www.npmjs.com/package/@mirco312312/react-imask

@uNmAnNeR is it required to explicitly import imask as esm?

@nfantone
Copy link

nfantone commented Aug 3, 2020

Same here. Trying to import react-imask from within a Next.js project doesn't seem to work.

@ghost
Copy link

ghost commented Aug 21, 2020

@MatheusRyuki had the same issue in SSR, also couldn't get babel to work well with the esm import.

So I removed the forced esm import: mirco312312@653bfc3

Published as quick-fix:
https://www.npmjs.com/package/@mirco312312/react-imask

@uNmAnNeR is it required to explicitly import imask as esm?

This works for me! Many thanks

@nghiepdev
Copy link

For Next.js

import dynamic from 'next/dynamic';

const IMaskInput = dynamic(
  () => import('react-imask').then(mod => mod.IMaskInput),
  {ssr: false},
);

@cgarrovillo
Copy link

Has anyone found an actively maintained alternative to this library? I think at this point this library takes away from the whole "reusability" nature of things

@adrianos10
Copy link

adrianos10 commented Dec 7, 2020

We are using next-transpile-modules for imask (https://www.npmjs.com/package/next-transpile-modules) in our project and when it was upgraded to v6.0.0 I am also encountering this issue. When using the previous version ([email protected]) everything works fine.

@umairhm
Copy link

umairhm commented Dec 14, 2020

We were getting the following error while running Jest tests in an Nx (Angular) environment.

Screen Shot 2020-12-14 at 5 57 52 PM

The configurations mentioned here helped us resolved the issue: https://github.com/thymikee/jest-preset-angular#transpile-js-files-through-babel-jest

@AlexBrasileiro
Copy link

For Next.js

import dynamic from 'next/dynamic';

const IMaskInput = dynamic(
  () => import('react-imask').then(mod => mod.IMaskInput),
  {ssr: false},
);

You save my day, thanks o/ (works on Next.js ^ 10.0.3)

@uNmAnNeR
Copy link
Owner

uNmAnNeR commented Feb 9, 2021

thanks guys, probably is fixed in 6.0.6

@uNmAnNeR uNmAnNeR closed this as completed Feb 9, 2021
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

No branches or pull requests

10 participants