-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Export issue for upgraded version. SyntaxError: Unexpected token 'export' #1835
Comments
I'm getting the same from 24.5.0 (updating from 18.1.6) |
You are currently importing
For a detailed explanation on how to import the utilities correctly, please refer to this link: Loading the Utilities Script. |
Thanks @rashadmehtab! @Ryan-Boustany yes, as @rashadmehtab says, the problem is that you have the following line somewhere in your tests/code:
Which file is that in? And what are you hoping to achieve with this? Utils has now changed so it no longer sets a global, so this approach to loading the utils will no longer work. It's now an ES module, which needs to be loaded in a particular way - again see the readme link that @rashadmehtab kindly shared 🙏🏻 |
@Ryan-Boustany I’ve recently done some contributions in this area, and specifically with Jest. 😃 A few things:
The above should just work, but the downside is that it comes with the utilities module pre-loaded, which is pretty big! If you want to load utilities asynchronously later on, making it work in Jest is unfortunately a little complicated (the async utilities script is a proper JS module, and Jest’s module support is still experimental). You’ll need to do two things to get async loading working in Jest:
Then use the React module that loads async instead of preloading utils: To just load the utils module directly if you don’t need the whole library, you can also do the following (pretty sure you’ll need the above Jest fixes for this, though): import libphonenumber from 'intl-tel-input/utils';
libphonenumber.isValidNumber(...); // or whatever you want to do with it Be careful to make sure you aren’t loading the utils twice in your bundle if you are doing this alongside the React component, though! Side note on changes to the package that would make this easier: @jackocnr Seeing how this affects users of this package in their tests tells me you have a better point than I thought about removing the string option for Another good way to make this easier for users might be to:
That way folks shouldn’t need any special Jest config for the async loading utils. |
Thanks for the suggestions! In another file I am importing it as such: How would I need to change the imports for this file? |
So, assuming you don’t want to do all the wacky stuff to get async utils working in Jest, you want to
|
Thank you @Mr0grog @jackocnr and @rashadmehtab for the assistance :) |
Plugin version
v24.5.1
Description
I was running v17 of intl-tel-input library on my repo I needed the latest version of libphonenumber so I updgraded my intl-tel-input to v24. I am now receiving these bugs in my test cases that have something to do with export. Does anyone have any idea why this might be occurring.
Any assistance on this would be greatly appreciated thank you!
Expected behaviour
My tests should be running without an export issue
Actual behaviour
My tests are failing due to an export issue
Initialisation options
I am using these versions in my devDependecies:
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"babel-jest": "^23.6.0",
"babel-loader": "^7.1.5",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-react-css-modules": "^3.4.2",
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"@babel/core": "^7.25.2"
"@babel/preset-env": "^7.25.4"
"jest": "^23.6.0",
"jest-enzyme": "^6.1.2",
"jest-html-reporter": "^3.10.2",
"jest-slow-test-reporter": "^1.0.0"
"ts-jest": "^23.0.0",
The text was updated successfully, but these errors were encountered: