I have a Django project I am attempting to get nightwatch JS setup on, but I can't seem to get around issues with selinum drivers.
I have a node_modules directory like this (showing important areas)
node_modules
.bin
chromedriver
geckodriver
In my root folder I have a test written like so, named custom_test.js:
module.exports = {
'NW test on Google' : function (client) {
client
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.assert.title('Google')
.assert.visible('input[type=text]')
.setValue('input[type=text]', 'Nightwatch JS')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('ol#rso li:first-child',
'Nightwatch.js | Node.js powered End-to-End testing framework')
.end()
}
}
Scripts in package.json:
"nightwatch": "./node_modules/.bin/nightwatch"
And just in case this is needed, here shows the devDependenices from chromedriver and geckdriver
"chromedriver": "^88.0.0",
"geckodriver": "^1.22.1",
And now nightwatch.json
{
"src_folders" : [""],
"webdriver" : {
"start_process": true,
"server_path": "node_modules/.bin/geckodriver",
"port": 9515
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "firefox"
}
}
}
}
When I run: npm run nightwatch custom_test.js I simplt get:
An error occurred while retrieving a new session: "Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line"
If I change the nightwatch.json file to point to the chromedriver I get this error:
{
"src_folders" : [""],
"webdriver" : {
"start_process": true,
"server_path": "node_modules/.bin/chromedriver",
"port": 9515
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "chrome"
}
}
}
}
An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
This is not making sense to me as the configuration is only telling me to run the installations of the drivers through npm install:
https://nightwatchjs.org/gettingstarted/configuration/
What am I doing wrong?
UPDATE
Changin the config to nightwatch.conf.js:
module.exports = {
// An array of folders (excluding subfolders) where your tests are located;
// if this is not specified, the test source must be passed as the second argument to the test runner.
src_folders: ["tests"],
webdriver: {
start_process: true,
port: 4444,
server_path: require('chromedriver').path,
cli_args: [
]
},
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
}
}
}
}
Provides this error:
An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
Here is the whole output:
npm run nightwatch custom_test.js
> exactestate#1.0.0 nightwatch /opt/project
> nightwatch "custom_test.js"
[Custom Test] Test Suite
========================
⚠ Error connecting to localhost on port 4444.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (221ms)
✖ custom_test
An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
Error: An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
at endReadableNT (_stream_readable.js:1187:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Error: An error occurred while retrieving a new session: "unknown error: cannot find Chrome binary"
at endReadableNT (_stream_readable.js:1187:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
SKIPPED:
- NW test on Google
npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! exactestate#1.0.0 nightwatch: `nightwatch "custom_test.js"`
npm ERR! Exit status 5
npm ERR!
npm ERR! Failed at the exactestate#1.0.0 nightwatch 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! /root/.npm/_logs/2021-02-09T17_02_25_145Z-debug.log
UPDATE WITH NPX
Starting: nightwatch custom_test.js
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module '/opt/project/nightwatch'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
UPDATE 3: WHOLE PACKAGE.JSON
{
"name": "exactestate",
"version": "1.0.0",
"description": "Modern, Secure, and Customizable Real Estate Management Software in the Cloud.",
"scripts": {
"build": "webpack --mode=production",
"build:dev": "webpack --mode=development",
"serve": "webpack-dev-server",
"test": "jest --colors --coverage --verbose ",
"nightwatch": "./node_modules/.bin/nightwatch"
},
"browserslist": [
"last 2 version",
"> 1%"
],
"dependencies": {
"#fortawesome/fontawesome-pro": "^5.13.0",
"axios": "^0.21.1",
"bootstrap": "^4.4.1",
"chart.js": "^2.9.4",
"chartjs-plugin-datalabels": "^0.7.0",
"cleave": "^1.0.0-alpha.10",
"crypto-js": "^4.0.0",
"datatables.net": "^1.10.20",
"gsap": "^3.2.6",
"intro.js": "^2.9.3",
"jquery": "^3.5.0",
"jspdf": "^1.5.3",
"jspdf-autotable": "^3.4.3",
"lodash": "^4.17.15",
"lodash-webpack-plugin": "^0.11.6",
"mobile-device-detect": "^0.3.3",
"moment": "^2.24.0",
"mousetrap": "^1.6.5",
"node": "^12.16.2",
"popper.js": "^1.16.1",
"qs": "^6.9.3",
"secure-web-storage": "^1.0.2",
"tiptap": "^1.27.0",
"tiptap-extensions": "^1.29.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"v-mask": "^2.1.0",
"validator": "^12.2.0",
"vue": "^2.6.11",
"vue-async-computed": "^3.8.2",
"vue-chartjs": "^3.5.1",
"vue-inputmask": "^0.2.1",
"vue2-perfect-scrollbar": "^1.5.0",
"vuedraggable": "^2.23.2",
"ws": "^7.3.0"
},
"devDependencies": {
"#babel/cli": "^7.8.4",
"#babel/core": "^7.11.6",
"#babel/plugin-transform-runtime": "^7.11.5",
"#babel/preset-env": "^7.11.5",
"#tweenjs/tween.js": "^18.5.0",
"#vue/test-utils": "^1.1.0",
"autoprefixer": "^9.7.6",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.5.2",
"babel-loader": "^8.1.0",
"babel-preset-es2015": "^6.24.1",
"chai": "^4.3.0",
"chromedriver": "^88.0.0",
"clean-webpack-plugin": "^3.0.0",
"co": "^4.6.0",
"co-mocha": "^1.2.2",
"compression-webpack-plugin": "^3.1.0",
"copy-webpack-plugin": "^5.1.1",
"core-js": "^3.6.5",
"css-loader": "^3.5.2",
"electron": "^11.2.3",
"fibers": "^4.0.2",
"file-loader": "^4.3.0",
"geckodriver": "^1.22.1",
"glob": "^7.1.6",
"gzip-loader": "0.0.1",
"imagemin-mozjpeg": "^8.0.0",
"imagemin-webpack-plugin": "^2.4.2",
"jest": "^26.5.3",
"jspdf": "^1.5.3",
"mini-css-extract-plugin": "^0.8.2",
"mocha": "^8.2.1",
"mocha-generators": "^2.0.0",
"nightmare": "^3.0.2",
"nightwatch": "^1.5.1",
"node-sass": "^4.14.1",
"postcss-import": "^12.0.1",
"postcss-loader": "^3.0.0",
"regenerator-runtime": "^0.13.5",
"sass": "^1.26.3",
"sass-loader": "^8.0.2",
"speed-measure-webpack-plugin": "^1.3.3",
"style-loader": "^1.1.4",
"url-loader": "^2.2.0",
"vue-jest": "^3.0.7",
"vue-loader": "^15.9.1",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.42.1",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-bundle-tracker": "^0.4.3",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ViaTechSystems/ExactEstate.git"
},
"bugs": {
"url": "https://github.com/ViaTechSystems/ExactEstate/issues"
},
"homepage": "https://github.com/ViaTechSystems/ExactEstate#readme"
}
Create a file in your root directory as nightwatch.conf.js and copy the below -
module.exports = {
// An array of folders (excluding subfolders) where your tests are located;
// if this is not specified, the test source must be passed as the second argument to the test runner.
src_folders: [],
webdriver: {
start_process: true,
port: 4444,
server_path: require('chromedriver').path,
cli_args: []
},
test_settings: {
default: {
desiredCapabilities: {
browserName: "chrome",
chromeOptions: {
args: ['disable-gpu', 'no-sandbox', 'headless']
}
}
}
}
}
Related
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",
...
}
}
}
Production build fails with the following error:
ValidationError: Invalid options object. CSS Loader has been initialised using an options object that does not match the API schema.
- options has an unknown property 'minimize'. These properties are valid:
object { url?, import?, modules?, sourceMap?, importLoaders?, localsConvention?, onlyLocals? }
at validate (/Users/username/Sites/projectname/node_modules/css-loader/node_modules/schema-utils/dist/validate.js:85:11)
at Object.loader (/Users/username/Sites/projectname/node_modules/css-loader/dist/index.js:34:28)
Using this webpack template: http://vuejs-templates.github.io/webpack/, updated to Webpack 4 and faced build issues, package.json:
{
"name": "projectname",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config webpack.config.js --port 3000 --hot",
"start": "npm run dev",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"#vue/cli-service": "^3.2.0",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
"cross-env": "^5.2.0",
"css-loader": "^3.2.1",
"jquery": "^3.3.1",
"moment": "^2.22.2",
"style-loader": "^1.0.1",
"swiper": "^4.5.0",
"v-tabs-router": "^1.4.0",
"vee-validate": "^2.1.0-beta.9",
"vue": "^2.5.2",
"vue-awesome-swiper": "^3.1.3",
"vue-backtotop": "^1.6.1",
"vue-carousel": "^0.18.0",
"vue-cleave-component": "^2.1.2",
"vue-instant": "^1.0.2",
"vue-jsonp": "^0.1.8",
"vue-magic-line": "^0.2.1",
"vue-masked-input": "^0.5.2",
"vue-resource": "^1.5.1",
"vue-router": "^3.0.2",
"vue-select": "^2.5.1",
"vue-slider-component": "^2.8.0",
"vue-smooth-scroll": "^1.0.13",
"vuejs-datepicker": "^1.5.3",
"vuelidate": "^0.7.4",
"vuex": "^3.0.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^5.0.2",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^3.2.0",
"node-notifier": "^5.1.2",
"node-sass": "^4.13.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^12.0.1",
"postcss-loader": "^3.0.0",
"postcss-url": "^8.0.0",
"rimraf": "^2.6.0",
"sass-loader": "^8.0.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^1.1.2",
"vue-loader": "^14.2.2",
"vue-resource": "^1.5.1",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.5.2",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
I've checked with grep -rl 'minimize' . in a project root, but didn't found any related options. Wth..
This has to do with a breaking change in the module. According to semver rules, a major change (first digit x of version x.y.z) is a breaking change.
In this case the old version syntax uses
{
loader: 'postcss-loader',
options: {
plugins: postCSSPlugins
}
}
whereas the new version in options uses nested postcssOptions before plugins
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: postCSSPlugins
}
}
}
I also encountered this error when updating to webpack 4 and using MiniCssExtractPlugin
I was able to eliminate the error and get a successful build by using an older version of ccs-loader
These versions worked for me
"devDependencies": {
"css-loader": "1.0.1",
OR
"css-loader": "^0.28.0",
css-loader 2* and 3* gave me the error.
UPDATE after testing publish: using the old version of the css-loader causes the css to fail to load when rendering the web site in a browser. So this appears to not be a solution.
I was having the same issue after I ran yarn upgrade --latest command.
It changed sass-loader version from 7.1.0 to 8.0.0. After that getting the same error.
There might be change in sass-loader options and due to that, this error occurred. You can check release: https://github.com/webpack-contrib/sass-loader/releases and updated options https://github.com/webpack-contrib/sass-loader
Try to remove/change sass-loader options, that can help you to resolve it.
Hope this can help, it would be great if can you share webpack.config.js file.
Cheers~
I had a similar problem upgrading to webpack 4. I used Vue.js CLI which generated a build/utils.js file that effectively has a configurable webpack based on whether I am in a development or a production environment.
Pertinent utils.js lines in auto generated (failing after upgrading) code:
var ExtractTextPlugin = require('extract-text-webpack-plugin')
exports.cssLoaders = function (options) {
options = options || {}
var cssLoader = {
loader: 'css-loader',
options: {
minimize: process.env.NODE_ENV === 'production',
sourceMap: options.sourceMap
}
}
// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
var loaders = [cssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ExtractTextPlugin.loader({
use: loaders,
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
scss: generateLoaders('sass'),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
}
I tried the simple, "Let's just update the module.":
var ExtractTextPlugin = require('mini-css-extract-plugin')
Which gave me the error that you had. After much messing around with the files, I used the "Easter Egg Troubleshooting Strategy", and found that I could do the following and get it to work. What worked was the following:
npm i extract-loader --save-dev
then modify build/utils.js:
exports.cssLoaders = function (options) {
options = options || {}
var cssLoader = {
loader: 'css-loader',
options: {
// minimize: process.env.NODE_ENV === 'production',
sourceMap: options.sourceMap
}
}
// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
var loaders = [cssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ['extract-loader'].concat(loaders)
// return ExtractTextPlugin.loader({
// use: loaders,
// fallback: 'vue-style-loader'
// })
} else {
return ['vue-style-loader'].concat(loaders)
}
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
scss: generateLoaders('sass'),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
}
Notice, I commented out line 9, which is the source of my error. I also removed my sole dependency to the mini-css-extract-plugin with the extract-loader module.
// minimize: process.env.NODE_ENV === 'production',
Now I have to figure out why eslint is not liking my Vue syntax.
I have written many components in vuetify that are reusable. I am using jest testing framework for unit testing. When I run 'npm run test', the test fails with 'SyntaxError: Unexpected identifier'.
All my babel config and jest config are in package.json file. When I create a spec file without any vuetify components, test works. But once I add vuetify, it distorts. I first used localValue from #vue/test-utils to consume vuetify. It didn't work. Then I used Vue.use(Vuetify) and still it didn't work.
package.json
{
"name": "xyz",
"version": "0.2.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test": "jest",
"clear_jest": "jest --clearCache"
},
"dependencies": {
"#contentful/rich-text-html-renderer": "^13.0.0",
"#storybook/addon-a11y": "^4.1.4",
"avoriaz": "^6.3.0",
"axios": "^0.18.0",
"axios-mock-adapter": "^1.16.0",
"contentful": "^7.3.0",
"deepdash": "^1.9.5",
"eslint": "^5.15.3",
"jest": "^24.5.0",
"jest-serializer-vue": "^2.0.2",
"json-server": "^0.14.2",
"lodash": "^4.17.11",
"moment": "^2.24.0",
"nightwatch": "^1.0.19",
"node-sass": "^4.11.0",
"purgecss": "^1.1.0",
"sass-loader": "^7.1.0",
"storybook-vue-router": "^1.0.2",
"tailwindcss-aspect-ratio": "^1.0.1",
"tailwindcss-gradients": "^1.1.0",
"tailwindcss-transition": "^1.0.5",
"vee-validate": "^2.2.2",
"vue": "^2.5.19",
"vue-faq-accordion": "^1.2.1",
"vue-jest": "^3.0.4",
"vue-router": "^3.0.2",
"vue-template-compiler": "^2.5.20",
"vuelidate": "^0.7.4",
"vuetify": "^1.5.7",
"vuex": "^3.1.0",
"vuex-persist": "^2.0.0"
},
"devDependencies": {
"#babel/core": "^7.3.4",
"#babel/preset-env": "^7.3.4",
"#storybook/addon-actions": "^4.1.0",
"#storybook/addon-links": "^4.1.0",
"#vue/cli-plugin-babel": "^3.2.0",
"#vue/cli-plugin-eslint": "^3.2.1",
"#vue/cli-service": "^3.2.0",
"#vue/test-utils": "^1.0.0-beta.29",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-preset-vue": "^2.0.2",
"chromedriver": "^2.46.0",
"concurrently": "^4.1.0",
"cross-env": "^5.2.0",
"cucumber": "^5.1.0",
"cucumber-html-reporter": "^4.0.5",
"cucumber-pretty": "^1.5.0",
"eslint": "^5.15.3",
"geckodriver": "^1.16.0",
"http-server": "^0.11.1",
"jest-transform-stub": "^2.0.0",
"mkdirp": "^0.5.1",
"nightwatch-api": "^2.1.3",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"vue-cli-plugin-storybook": "^0.5.0",
"vue-cli-plugin-svg": "^0.1.2",
"vue-cli-plugin-tailwind": "^0.4.0",
"vue-cli-plugin-vuetify": "^0.5.0",
"vue-svg-loader": "^0.11.0",
"vue-template-compiler": "^2.5.21",
"vuetify": "^1.5.7",
"vuetify-loader": "^1.0.5"
},
"babel": {
"presets": [
[
"#babel/preset-env",
{
"modules": "commonjs",
"targets": {
"node": "current"
}
}
]
]
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"> 5%",
"last 5 versions",
"not ie <= 10"
],
"jest": {
"moduleFileExtensions": [
"js",
"vue"
],
"moduleNameMapper": {
"^#/(.*)$": "<rootDir>/src/$1",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
},
"snapshotSerializers": [
"<rootDir>/node_modules/jest-serializer-vue"
],
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!vuetify)"
],
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
}
}
}
Toolbar.vue
<template>
<div>
<v-toolbar class="toolbar" height="70">
<v-toolbar-title class="toolbar-title" #click="goToHome()">{{ title }}</v-toolbar-title>
<v-spacer></v-spacer>
<Profile v-if="user.status"/>
</v-toolbar>
</div>
</template>
<script>
import Profile from '#/components/Profile'
export default {
props: {
title: {
type: String,
required: true
}
},
components: {
Profile
},
methods: {
goToHome() {
this.$router.push('/home')
}
}
}
</script>
<style scoped lang="postcss">
.toolbar-title {
color: #ffffff;
text-decoration: none;
cursor: pointer;
}
.toolbar {
#apply bg-secondary !important;
}
</style>
Toolbar.spec.js
import { shallowMount } from '#vue/test-utils'
import Toolbar from '#/components/List'
import Vuetify from 'vuetify'
import Vue from 'vue'
describe('Toolbar.vue', () => {
let wrp
beforeEach(() => {
Vue.use(Vuetify)
wrp = shallowMount(Toolbar)
})
it('Toolbar is a vue instance', () => {
expect(wrp.isVueInstance()).toBeTruthy()
})
})
Desired result should be:
> jest
PASS test/unit/component/Toolbar.spec.js
Toolbar.vue
√ Toolbar is a vue instance (21ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 4.882s
Ran all test suites.
Actual:
C:\rahul13615>npm run test
> myproject#0.2.0 test C:\rahul13615\
> jest
FAIL test/unit/component/Toolbar.spec.js
● Test suite failed to run
C:\rahul13615\node_modules\#babel\runtime-corejs2\helpers\esm\typeof.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import _Symbol$iterator from "../../core-js/symbol/iterator";
^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/#jest/transform/build/ScriptTransformer.js:451:17)
at ScriptTransformer.transform (node_modules/#jest/transform/build/ScriptTransformer.js:493:19)
at Object.<anonymous> (node_modules/vuetify/dist/vuetify.js:91:39)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 6.328s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myproject#0.2.0 test: `jest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myproject#0.2.0 test 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:
#barakbd is actually right, don't know why his answer is downvoted.
You can first try manually clearing cache with jest --clearCache and if that doesn't work, restart should help which seems to clear another cache that also affected jest.
Restart solved the issue for me.
Had the same error message with vue-test-utils via jest. Cause was of course different, mine was first import "highlight.js/styles/atom-one-dark.css". After commenting out, something other errored same style. Turned out that a cyclic dependency was the cause. In my case, main.ts exported a function used by store.ts. And main.ts used exported from store.ts. Moved exported function to utils.ts, error disappeared.
Restart computer.
I kid you not, I had the same error, tried figuring it out for 2 days. A full system restart solved the issue.
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"
}
I keep getting this really annoying error in webpack and even when I run webpack --display-error-details, I get no errors. But anytime I run webpack-dev-server I get the following error. I really can't see where I am going wrong in my configuration.
Entry module not found: Error: Cannot resolve 'file' or 'directory'
./frontend/app.jsx
module.exports = {
context: __dirname,
entry: './frontend/app.jsx',
output: {
filename: 'bundle.js',
path: __dirname
},
module: {
loaders: [
{
test: [ /\.js$/, /\.jsx$/],
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.scss' ]
}
};
{
"name": "basicapp",
"version": "1.0.0",
"description": "",
"main": "app.jsx",
"author": "",
"license": "ISC",
"scripts": {
"start": "webpack-dev-server --env development",
"dev-server": "nodemon ./server.js localhost 8080",
"build": "webpack --env production"
},
"dependencies": {
"babel-cli": "^6.24.0",
"babel-core": "^6.24.0",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"css-loader": "^0.27.3",
"express": "^4.15.2",
"express-graphql": "^0.6.3",
"lodash": "^4.17.4",
"node-sass": "^4.5.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^5.0.3",
"react-router": "^4.0.0",
"redux": "^3.6.0",
"sass-loader": "^6.0.3",
"webpack": "^2.3.2"
},
"devDependencies": {
"html-webpack-plugin": "^2.28.0",
"node-sass": "^4.5.1",
"nodemon": "^1.11.0",
"sass-loader": "^6.0.3"
}
}
Webpack may not be treating __dirname as you want it to and may be resolving it to / instead. Try adding this to your webpack config:
{
node: {
__dirname: true
}
}
this can be because of multiple reasons the best way to identify the exact issue is to tryout the below two commands:
if you are running webpack 1/2 alone then use the snippet:
webpack --display-error-details
if you are running the webpack dev server then use the snippet:
webpack-dev-server --display-error-details
this would provide a detailed error report in the console