I'm getting this error when trying to run yarn run dev --port=4000
Here is the error:
Module build failed (from ./node_modules/babel-loader/lib/index.js): friendly-errors 16:52:26
Error: /Users/jacob/code/artistrepublik/elite-reviews/.nuxt/client.js: Cannot find module '#babel/preset-env/lib/utils'
Require stack:
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/polyfills-plugin.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/module-types.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/configuration.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/config/files/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/nuxt-route-meta/dist/index.js
- /Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/core/dist/core.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at n (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/jiti/dist/v8cache.js:2:2364)
at PluginPass.Program (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#nuxt/babel-preset-app/src/polyfills-plugin.js:15:34)
at newFn (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/visitors.js:175:21)
at NodePath._call (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/path/context.js:92:31)
at TraversalContext.visitQueue (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:116:16)
at TraversalContext.visitSingle (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:85:19)
at TraversalContext.visit (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/context.js:144:19)
at Function.traverse.node (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/index.js:82:17)
at traverse (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/traverse/lib/index.js:62:12)
at transformFile (/Users/jacob/code/artistrepublik/elite-reviews/node_modules/#babel/core/lib/transformation/index.js:107:29)
at transformFile.next (<anonymous>)
friendly-errors 16:52:26
# multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
Here is my package.json:
{
"name": "my-project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt -r dotenv/config",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"test": "jest"
},
"dependencies": {
"#nuxtjs/axios": "^5.12.5",
"#nuxtjs/dotenv": "^1.4.1",
"#nuxtjs/pwa": "^3.3.4",
"#paypal/paypal-js": "^1.0.5",
"#vue/babel-preset-app": "^4.5.10",
"core-js": "^3.8.3",
"es6-promise": "^4.1.1",
"lodash": "^4.17.20",
"moment": "latest",
"moment-timezone": "^0.5.32",
"noty": "^3.2.0-beta",
"nuxt": "^2.14.12",
"nuxt-i18n": "^6.18.0",
"nuxt-route-meta": "^1.0.3",
"nuxt": "^2.14.6",
"nuxt-i18n": "^6.15.1",
"nuxt-route-meta": "^1.0.1",
"nuxt-stripe-module": "^3.0.1",
"object-to-formdata": "^4.1.0",
"pluralize": "latest",
"vee-validate": "^3.4.5",
"sib-api-v3-sdk": "github:sendinblue/APIv3-nodejs-library",
"vue-carousel": "^0.18.0",
"vue-chartist": "^2.2.1",
"vue-material-design-icons": "^4.11.0",
"vuejs-noty": "^0.1.3",
"vue-plyr": "^7.0.0",
"vuetify-media-player": "^0.8.1"
},
"devDependencies": {
"#babel/core": "^7.12.10",
"#mdi/font": "^5.9.55",
"#nuxt/types": "^2.14.12",
"#nuxtjs/style-resources": "^1.0.0",
"#nuxtjs/vuetify": "^1.11.3",
"#vue/test-utils": "^1.1.2",
"babel-jest": "^26.6.3",
"babel-plugin-component": "^1.1.0",
"cross-env": "^5.2.0",
"dotenv": "^8.2.0",
"jest": "^26.6.3",
"material-design-icons-iconfont": "^6.1.0",
"node-sass": "^4.14.1",
"nodemon": "^1.18.9",
"sass-loader": "^7.3.1",
"vue-jest": "^3.0.4"
}
}
And here is my .babelrc:
{
"env": {
"test": {
"presets": [
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
}
}
I have tried deleting the node_modules folder along with removing the yarn.lock file with no luck. The babel version looks correct. This error only popped up after me playing around with some code (not the package.json) - which is an unrelated error.
Any help would be appreciated!
#babel/preset-env updated,
use old version 7.12.17
https://www.npmjs.com/package/#babel/preset-env/v/7.12.17
This issue drove me crazy for a few hours too.
The solution is to add to nuxt.config.js into build section:
/*
** Build configuration
*/
build: {
babel: {
presets(env, [ preset, options ]) {
return [
[ "#babel/preset-env", options ]
]
}
},
Make sure you have that thing installed:
npm install --save-dev #babel/preset-env
or in your case with yarn
Updated:
Then I encountered another error
regeneratorRuntime is not defined
Here is working part from my config.nuxt.js
build: {
babel: {
presets({isServer}) {
const targets = isServer ? { node: 'current' } : { ie: 11 }
return [
[ require.resolve("#babel/preset-env"), { targets } ]
]
},
plugins: [
"#babel/syntax-dynamic-import",
"#babel/transform-runtime",
"#babel/transform-async-to-generator"
]
},
I did the following:
npm uninstall #babel/preset-env
npm install #babel/preset-env#7.12.13
The latest version seems to have this issue resolved, try updating Nuxt to v2.15.2
https://nuxtjs.org/docs/release-notes
lib/utils.js was dropped for #babel/preset-env#7.13.0 and above
as stated above installing the old 7.12.17 might work
for monorepos it may not be enough. upgrading nuxtjs to 2.15.x did the trick for me
I had same error when deploying to ElasticBeanstalk
Error: /var/app/current/.nuxt/client.js: Cannot find module '#babel/preset-env/lib/utils'
upgrading from "nuxt": "v2.14.12", to "nuxt": "v2.15.2", seem to have solved the problem
npm uninstall #babel/preset-env
npm install #babel/preset-env#7.12.17
I just had the same problem, There's some issue with the newest #babel/preset-env within the Nuxt.
install the old version and it should work just fine
npm i #babel/preset-env#7.12.17 -S
You can try to do:
// package.json
"devDependencies": {
+ "#babel/preset-env": "7.12.17",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"node-sass": "^4.14.1",
"sass-loader": "^8.0.2",
"style-loader": "^1.0.0"
},
// package-lock.json
"#babel/preset-env": {
+"version": "7.12.17",
...,
"#nuxt/babel-preset-app": {
"requires": {
"#babel/preset-env": "7.12.17",
...
}
}
}
Related
I get this error when I run npm test. I've looked at a number of posts, solutions, etc. that suggest making edits to package.json, babel.config.js, jest.config.js and I still receive this error. I thought it could be a version issue with React Native, but I'm on the latest version 0.60.4 and it's mentioned in a few issues that this is solved in master. Perhaps I'm overlooking something, but I'm coming up short on what else it could be.
The following is the test that fails as a result:
import { geolocationRequest } from '../location';
let mockGeoCoding = jest.fn();
jest.mock('react-native-geocoding', () => ({
openURL: mockGeoCoding,
}));
describe('geolocationRequest', () => {
it('creates a properly formatted action', () => {
expect(geolocationRequest()).toMatchSnapshot();
})
})
Thoughts?
package.json
{
"name": "<app-name>",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start --config ../../../../rn-cli.config.js",
"start:ios": "react-native run-ios",
"start:android": "react-native run-android",
"clean:ios": "cd ios/ && pod deintegrate && pod install",
"clean:android": "cd android && ./gradlew clean",
"test": "jest --watch",
"test:coverage": "jest --coverage && open coverage/lcov-report/index.html",
"fix": "eslint --fix .",
"lint:ts": "tslint --fix --project ./tsconfig.json",
"lint:fix": "npm run lint:ts --fix",
"lint:check": "tslint --type-check --project"
},
"dependencies": {
"#react-native-community/async-storage": "1.4.2",
"appcenter": "1.12.2",
"appcenter-analytics": "1.12.2",
"appcenter-crashes": "1.12.2",
"axios": "^0.19.0",
"expo-font": "4.0.0",
"polyline": "0.2.0",
"react": "16.8.6",
"react-devtools": "3.6.1",
"react-native": "0.60.*",
"react-native-animatable": "1.3.2",
"react-native-auth0": "1.4.2",
"react-native-easy-grid": "0.2.1",
"react-native-elements": "1.1.0",
"react-native-geocoding": "0.3.0",
"react-native-gesture-handler": "1.3.0",
"react-native-maps": "0.24.2",
"react-native-vector-icons": "6.4.2",
"react-navigation": "3.9.1",
"react-redux": "7.1.0",
"redux": "4.0.0",
"redux-thunk": "2.3.0",
"scheduler": "0.14.0"
},
"devDependencies": {
"#babel/plugin-proposal-class-properties": "^7.5.5",
"#babel/preset-typescript": "^7.3.3",
"#types/enzyme": "^3.10.3",
"#types/enzyme-adapter-react-16": "^1.0.5",
"#types/jest": "^24.0.17",
"#types/polyline": "0.1.28",
"#types/react": "16.8.13",
"#types/react-native": "0.57.43",
"#types/react-native-auth0": "1.3.0",
"#types/react-native-vector-icons": "6.4.0",
"#types/react-redux": "^7.1.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"babel-jest": "24.3.1",
"babel-preset-expo": "5.1.1",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.4.0",
"eslint": "5.15.1",
"eslint-config-airbnb": "17.1.0",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.12.4",
"jest": "^24.3.1",
"jest-fetch-mock": "^2.1.2",
"jest-localstorage-mock": "^2.4.0",
"metro-react-native-babel-preset": "0.53.0",
"react-dom": "^16.8.6",
"react-native-typescript-transformer": "1.2.12",
"react-test-renderer": "^16.6.3",
"redux-mock-store": "^1.5.3",
"ts-jest": "^24.0.2",
"tslint": "5.16.0",
"typescript": "3.4.3"
},
"jest": {
"preset": "react-native"
}
}
jest.config.js
module.exports = {
"preset": 'react-native',
"verbose": true,
"setupFilesAfterEnv": ["<rootDir>/__tests__/setup.js", "jest-localstorage-mock"],
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.tsx?$": "ts-jest",
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"testPathIgnorePatterns": ['/node_modules/'],
"snapshotSerializers": ["enzyme-to-json/serializer"],
// "collectCoverageFrom": ["src/**/*.tsx"],
"collectCoverage": true,
};
babel.config.js
module.exports = {
"presets": ["module:metro-react-native-babel-preset"]
}
I've been struggling with the same issue.
Based on this comment on github From harudev
[...] So I tested some files to test project, and find out "react-native.config.js" file was the reason.
If there is someone suffered this issue, try to remove file or options from one of your "*.config.js" 😅
So I did remove all of my *.config.js file and the error is now gone.
Hopefully this could help you.
Note that you can reproduce the behavior of the *.confing.js file with package.json
For me this happened at an update of RN from 0.59.10 to 0.61.4.
I tried several fixes but nothing worked.
The only workaround that I've found was to set metro.config.js as below:
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/node_modules\/.*\/node_modules\/react-native\/.*/,
]),
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
Source: jamalx31's answer from here:
https://github.com/facebook/react-native/issues/24065#issuecomment-537489786
The issue is reported and documented here:
https://github.com/facebook/react-native/issues/24065
and here:
https://github.com/facebook/react-native/issues/23943
Had the same error, after a good amount of soul searching (google searching)
i just ran npx react-native start oposed to runing my local react-native.
I just upgraded from RN 0.55.4 to 0.59.3.....now Im getting following error:
Error: Unable to resolve module metro/src/lib/bundle-modules/HMRClient from ....\node_modules\react-native\Libraries\Utilities\HMRClient.js: Module metro/src/lib/bundle-modules/HMRClient does not exist in the Haste module map
The HMRClient.js file does include the following require statement: const MetroHMRClient = require('metro/src/lib/bundle-modules/HMRClient');.....and I cant see that path beginning with 'metro' anywhere so I guess I need to add it somehow. There is also another require statement as follows: const invariant = require('invariant'); ....no file name 'invariant' exists either.
Facebook say this was fixed back in 0.53.0 master but looks like its back
https://github.com/facebook/react-native/issues/17742
Below is my package.json
{
"name": "xs",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"flow": "flow",
"flow start": "flow start",
"flow stop": "flow stop",
"flow status": "flow status",
"flow coverage": "flow coverage"
},
"dependencies": {
"firebase": "^5.11.1",
"flow": "^0.2.3",
"flow-bin": "^0.65.0",
"prop-types": "^15.6.1",
"react": "16.8.3",
"react-native": "0.59.3",
"react-native-elements": "^0.19.0",
"react-native-google-places-autocomplete": "^1.3.9",
"react-native-maps": "git://github.com/react-native-community/react-native-maps.git#master",
"react-native-switch": "^1.4.0",
"react-native-vector-icons": "^4.5.0",
"react-navigation": "^2.5.5",
"react-redux": "^5.1.0",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"babel-eslint": "^8.2.6",
"babel-preset-flow": "^6.23.0",
"eslint": "^4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.13.0",
"prettier-eslint": "^8.8.2",
"#babel/core": "^7.4.3",
"#babel/runtime": "^7.4.3",
"babel-jest": "^24.7.1",
"jest": "^24.7.1",
"metro-react-native-babel-preset": "^0.53.1",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
Please help!
p.s. the below suggestion does not work
To resolve try the following:
1. Clear watchman watches: watchman watch-del-all.
2. Delete the node_modules folder: rm -rf node_modules && npm install.
3. Reset Metro Bundler cache: rm -rf /tmp/metro-bundler-cache-* or npm start -- --reset-cache.
4. Remove haste cache: rm -rf /tmp/haste-map-react-native-packager-*.
Pay attention when running npm install to see if there is any need for a specific version of something.
First check babel config files then if it doesn't work try the changes in package.json.
Try config files and deps as below.
This is a config that worked for me for an update from 0.54 to 0.59.5:
package.json:
" dependencies": {
"react": "16.8.3",
"react-native": "0.59.5",
// ...
},
"devDependencies": {
"#babel/core": "^7.0.0-0",
"babel-core": "^7.0.0-bridge.0",
"metro-react-native-babel-preset": "0.53.0",
"react-test-renderer": "16.6.3",
// ...
}
babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
.babelrc:
{
"presets": ["module:metro-react-native-babel-preset"]
}
The only useful info I could find in the RN release notes about babel and metro changes was at [0.57] here:
https://github.com/react-native-community/releases/blob/master/CHANGELOG.md
UPDATE NOTE:
Trying config files as the ones from a new working project (created with 0.59.9) doesn't seem to work for an update from 0.54 to 0.59
babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
metro.config.js:
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
and no .babelrc file.
package.json:
"devDependencies": {
"#babel/core": "^7.4.5",
"#babel/runtime": "^7.4.5",
"metro-react-native-babel-preset": "^0.54.1",
},
I'm trying to add unit testing to an existing vue project via jest, but when I attempt to run my first test I get an error that says
Vue packages version mismatch:
- vue#2.5.16
- vue-template-compiler#2.6.6
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader#>=10.0, simply update vue-template-compiler.
If you are using vue-loader#<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.
But looking at my packages, my current vue version is 2.6.6 not 2.5.16. I have no idea where it's seeing this 2.5.16 version. I don't have vue installed globally, only #vue/cli#3.4.0. Any help would be appreciated. Below you can find my package.json that contains my jest configuration.
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"dependencies": {
"#babel/core": "^7.4.0",
"#tinymce/tinymce-vue": "^1.1.0",
"#types/bootstrap": "^3.3.40",
"#types/jest": "^24.0.11",
"#types/jquery": "^2.0.51",
"#types/jquery.validation": "^1.16.5",
"#types/jqueryui": "^1.12.6",
"#types/kendo-ui": "^2018.3.0",
"#types/knockout": "^3.4.60",
"#types/moment": "^2.13.0",
"axios": "^0.18.0",
"axios-cache-adapter": "^2.1.1",
"browser-detect": "^0.2.28",
"es6-promise": "^4.2.5",
"file-saver": "^1.3.8",
"knockout": "^3.4.2",
"moment-timezone": "^0.5.23",
"query-string": "^6.2.0",
"tinymce-vue": "^1.0.0",
"url-search-params-polyfill": "^5.0.0",
"vee-validate": "^2.1.3",
"vue": "^2.6.6",
"vue-class-component": "^6.3.2",
"vue-multiselect": "^2.1.3",
"vue-notification": "^1.3.13",
"vue-property-decorator": "^7.2.0",
"vue-router": "^3.0.2",
"vuejs-datepicker": "^1.5.4",
"vuex": "^3.0.1",
"vuex-persistedstate": "^2.5.4"
},
"scripts": {
"dev": "webpack --mode development --watch --hot",
"test": "npm run test:unit",
"test:unit": "jest",
"build": "webpack --mode production",
"output": "webpack --profile --json > stats.json"
},
"devDependencies": {
"#types/file-saver": "^1.3.1",
"#vue/test-utils": "^1.0.0-beta.29",
"babel-core": "^6.26.3",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-3": "^6.24.1",
"css-loader": "^1.0.1",
"hard-source-webpack-plugin": "^0.13.1",
"jest": "^23.4.2",
"node-sass": "^4.10.0",
"printd": "^1.0.1",
"sass-loader": "^7.1.0",
"ts-jest": "^23.10.5",
"ts-loader": "^4.5.0",
"typescript": "^3.2.1",
"uglifyjs-webpack-plugin": "^2.0.1",
"vue-jest": "^3.0.4",
"vue-loader": "^15.4.2",
"vue-template-compiler": "^2.6.6",
"webpack": "^4.28.4",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.1.2",
"webpack-hot-middleware": "^2.24.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"ts",
"json",
"vue"
],
"moduleDirectories": [
".",
"<rootDir>/Scripts",
"<rootDir>/Scripts/VueModules",
"<rootDir>/Scripts/VueModules/SharedComponents",
"<rootDir>/Scripts/VueModules/Candidates/",
"node_modules"
],
"moduleNameMapper": {
"^#candidates$": "<rootDir>/Scripts/VueModules/Candidates",
"^#shared$": "<rootDir>/Scripts/VueModules/SharedComponents",
"^#app$": "<rootDir>/Scripts/VueModules",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/Scripts/VueModules/__mocks__/fileMock.js",
"\\.(css|less|scss|sass)$": "<rootDir>/Scripts/VueModules/__mocks__/styleMock.js"
},
"transform": {
".*\\.(vue)$": "vue-jest",
"^.+\\.tsx?$": "ts-jest"
},
"transformIgnorePatterns": [
"node_modules/(?!vue)"
],
"testURL": "http://localhost/",
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$"
}
}
You have "vue": "^2.6.6", and "vue-template-compiler": "^2.6.6", in your package.json meaning any version matching 2.6.6 or higher will be installed that explain the vue#2.5.16. Your package-lock.json file set the current version to which the package has been updated to, you can verify from there which version both vue and vue-template-compiler
You can run npm update or npm install vue-template-compiler#2.5.16 --save-dev to get both on the same version
Running the following command helped me
npm install vue-template-compiler#2.5.16 --save-dev
NB. Replace the version number with the right version that you need. In my case, the version of vue was 2.5.16 and vue-template-compiler was 2.5.13 hence I updated the vue-template-compiler to the version of the vue.
Hope this helps someone
Vue packages version mismatch error fix
npm update fixed the same problem for me.
Add the following lines to your Package.json
"vue-template-compiler": "^2.6.12"
and then run npm install in terminal.
I've searched high and low for an answer. I suspect that it is a .babelrc issue, but I can't find an answer that works.
The app runs just fine, but as I found out, both Jest and Rollup really depend on .babelrc. The other possible culprit is Leaflet. Of all the components that I build and test, only the one containing Leaflet and vue2-leaflet seem to have this problem. Considering I'm working on a mapping app, this is critical for me.
I'm posting here, because I can't prove anything. And there are a number of other folks that have seen similar problems.
Terminal Output:
nr test:unit
> cxl-vue-leaflet#3.0.1-SNAPSHOT test:unit /Users/dan.mahoney/Projects/cxl-vue-leaflet
> NODE_ENV=testing BABEL_DISABLE_CACHE=1 jest --verbose --no-cache
Determining test suites to run...
# Starting...
# 1 test suites found.
# FAIL src/components/__test__/specs/cxl-vue-leaflet.spec.js
#
# /Users/dan.mahoney/Projects/cxl-vue-leaflet/node_modules/vuetify/lib/index.js:1
#
# ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Vuetify from './components/Vuetify';
# ^^^^^^^
#
# SyntaxError: Unexpected identifier
#
# Stack:
#
# at new Script (vm.js:85:7)
1..0
# Test Suites: 0% , 1 failed, 1 total
# Tests: 0 total
# Time: 2.088s
# Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cxl-vue-leaflet#3.0.1-SNAPSHOT test:unit: `NODE_ENV=testing BABEL_DISABLE_CACHE=1 jest --verbose --no-cache`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cxl-vue-leaflet#3.0.1-SNAPSHOT test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/dan.mahoney/.npm/_logs/2019-03-08T21_06_53_748Z-debug.log
.babelrc:
{
"sourceMaps": true,
"presets": [
[
"#babel/preset-env",
]
],
"env": {
"test": {
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
}
},
"plugins": [
"transform-es2015-modules-commonjs",
["add-module-exports", {
"vuetify": {
"transform": "vuetify/es5/components/${member}",
"preventFullImport": "false"
},
}],
]
}
Jest config in package.json:
"jest": {
"transformIgnorePatterns": [
"<rootDir>/node_modules/"
],
"moduleFileExtensions": [
"js",
"vue"
],
"moduleNameMapper": {
"^#/(.*)$": "<rootDir>/src/$1",
"^.+\\.(css)$": "identity-obj-proxy"
},
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
"^.+\\.vue$": "vue-jest",
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
},
"reporters": [
"jest-tap-reporter"
],
"collectCoverageFrom": [
"**/components/*.vue",
"!**/node_modules/**"
]
},
Dependencies:
"dependencies": {
"get-value": "^3.0.1",
"leaflet": "^1.4.0",
"leaflet.icon.glyph": "^0.2.0",
"moment": "^2.23.0",
"vue-moment": "^4.0.0",
"vue2-leaflet": "^2.0.2",
"vue2-leaflet-markercluster": "^3.0.0",
"vuetify": "^1.5.5"
},
"devDependencies": {
"#babel/core": "^7.3.4",
"#babel/plugin-proposal-object-rest-spread": "^7.3.4",
"#babel/plugin-transform-runtime": "^7.3.4",
"#babel/preset-env": "^7.3.4",
"#vue/cli-service": "^3.5.0",
"#vue/test-utils": "^1.0.0-beta.28",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.3.1",
"babel-plugin-add-module-exports": "^1.0.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-source-map-support": "^2.0.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-imports": "^1.4.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"chromedriver": "^2.38.3",
"eslint": "^5.15.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-standard": "^12.0.0",
"eslint-config-strict": "^14.0.1",
"eslint-config-strict-es": "^1.0.4",
"eslint-detailed-reporter": "^0.7.3",
"eslint-import-resolver-webpack": "^0.11.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-html": "^5.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.1.3",
"eslint-plugin-leon-require-jsdoc": "0.0.1",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.1.0",
"eslint-plugin-vue-a11y": "0.0.28",
"growl": "^1.10.2",
"husky": "^1.3.1",
"identity-obj-proxy": "^3.0.0",
"is-image": "^2.0.0",
"jest": "^24.3.1",
"jest-tap-reporter": "^1.9.0",
"jest-transform-stub": "^2.0.0",
"jest-vue-preprocessor": "^1.5.0",
"jsdoc": "^3.5.5",
"jsdoc-vue": "^1.0.0",
"jsdom": "^13.0.0",
"jsdom-global": "^3.0.2",
"material-design-icons-iconfont": "^4.0.2",
"minimist": "^1.2.0",
"nightwatch": "^1.0.11",
"npm-merge-driver": "^2.3.5",
"parse5": "^5.1.0",
"raf": "^3.4.0",
"require-extension-hooks": "^0.3.2",
"require-extension-hooks-babel": "^0.1.1",
"require-extension-hooks-vue": "^2.0.0",
"rollup": "^1.6.0",
"rollup-plugin-analyzer": "^3.0.0",
"rollup-plugin-babel": "^4.3.0",
"rollup-plugin-babel-minify": "^7.0.0",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-postcss": "^2.0.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-vue": "^4.3.2",
"selenium": "^2.20.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"tap-summary": "^4.0.0",
"vue": "^2.6.8",
"vue-jest": "^3.0.4",
"vue-loader": "^15.7.0",
"vue-meta": "^1.5.8",
"vue-template-compiler": "^2.6.8",
"vuepress": "^1.0.0-alpha.42",
"vuepress-jsdoc": "^1.0.3",
"vuetify-loader": "^1.0.8"
},
I'm really at a loss here. Thanks for any help.
By default, Jest doesn't transform anything in node_modules (where vuetify package lives), but you actually need it to run vuetify through the configured babel-jest transform so that the imports could be transpiled. To do that, use this config in jest.config.js:
module.exports = {
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!vuetify)'
],
...
}
A Pull Request was just submitted to document this pitfall.
For anyone still experiencing this with Vue 3/Vuetify 3, the fix for me was similar, but I wasn't using many of the packages in the original question:
Jest config
"jest": {
"preset": "#vue/cli-plugin-unit-jest",
"transform": {
"^.+\\.vue$": "#vue/vue3-jest",
"^.+\\.(js|mjs)$": "babel-jest"
},
"transformIgnorePatterns": ["/node_modules/(?!(vuetify)/)"]
// plus some globals and a module alias
}
Babel config
module.exports = {
presets: [
'#vue/cli-plugin-babel/preset',
],
};
Dependency versions
"dependencies": {
"vue": "^3.2.31",
"vuetify": "^3.0.4",
"#vue/cli-plugin-babel": "^5.0.8",
"#vue/cli-plugin-unit-jest": "~5.0.8",
"#vue/cli-service": "~5.0.1",
"#vue/compiler-sfc": "^3.0.7",
"#vue/test-utils": "^2.2.6",
"#vue/vue3-jest": "^27.0.0-alpha.4",
"jest": "^27.5.1"
}
The trick was configuring the transform/transformIgnorePatterns as we had not previously needed to transform any Node modules. This fixed the Jest encountered an unexpected token/ SyntaxError: Cannot use import statement outside a module
I did still run into an issue where I could not import Vuetify components in my test files, I would get the following error:
Cannot find module 'vuetify/components' from 'tests/unit/InfoWindow/sections/DisplayFields/ScheduleDisplay.spec.js'
1 | import {shallowMount} from '#vue/test-utils';
2 | import {createVuetify} from 'vuetify';
> 3 | import * as components from 'vuetify/components';
| ^
4 | import * as directives from 'vuetify/directives';
I'm not sure of the cause, but the solution was to add explicit mappings to the Jest config:
"moduleNameMapper": {
"^vuetify/components$": "<rootDir>/node_modules/vuetify/lib/components/index.mjs",
"^vuetify/directives$": "<rootDir>/node_modules/vuetify/lib/directives/index.mjs"
}
Preface: I am new to Javascript, Babel and React-Native.
I have been developing my app using the TodoMVC example from the relay source. I was wondering if it's possible to get React-Native + Relay to work together easily?
I setup my babelRelayPlugin and added it to my .babelrc. I installed the npm packages for "react-relay":"^0.7.3" and "babel-relay-plugin": "^0.7.3" but after running "npm install" and "react-native start" I either get an error saying "Unrecognized module 'react-relay'" OR "Relay is not defined".
From reading this thread and looking at the last comment ( https://github.com/facebook/relay/issues/26#issuecomment-194570137 ) it looks like at the moment I should just use TodoMVC as my base for new React-Native + Relay projects.
Is this correct?
Here is my .babelrc
{
"env": {
"development": {
"passPerPreset": true,
"presets": [
{
"plugins": [
"./plugins/babelRelayPlugin"
]
},
"react-native"
]
},
"server": {
"plugins": [
"./plugins/babelRelayPlugin"
],
"presets": [
"es2015",
"stage-0"
]
}
}
}
Here is my package.json
{
"name": "testApp",
"version": "1.0.0",
"private": true,
"scripts": {
"clean:babelrc": "find ./node_modules -name react-packager -prune -o -name '.babelrc' -print | xargs rm -f",
"postinstall": "npm run clean:babelrc",
"start": "BABEL_ENV=server babel-node ./server.js",
"update-schema": "babel-node ./scripts/updateSchema.js"
},
"dependencies": {
"babel-preset-es2015": "^6.5.0",
"babel-preset-react-native": "^1.5.1",
"babel-preset-stage-0": "^6.5.0",
"babel-relay-plugin": "^0.7.3",
"express": "4.13.4",
"express-graphql": "0.4.9",
"graphql": "0.4.17",
"graphql-relay": "0.3.6",
"moment": "^2.12.0",
"node-fetch": "^1.4.1",
"react": "^0.14.5",
"react-native": "^0.22.2",
"react-native-animatable": "^0.5.2",
"react-native-aws3": "0.0.1",
"react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git",
"react-native-console-panel": "0.0.7",
"react-native-contacts": "^0.2.3",
"react-native-keyboard-aware-scroll-view": "0.0.6",
"react-relay": "^0.7.3",
"sync-request": "^3.0.0",
"uuid-v4": "^0.1.0"
},
"devDependencies": {
"babel-cli": "^6.6.4",
"flow-bin": "^0.22.1"
},
"engines": {
"npm": ">=3"
}
}
I managed to fix the issue. I added "babel-core": "^6.7.6" as a dev dependency. Removed all the scripts and cloned the project from git to a new folder. Everything runs perfectly now!