Cypress Task: The plugins file is missing or invalid - javascript

When I added my custom task I started getting some errors and I'm not sure how to solve it. I was following the example from RWA: https://github.com/cypress-io/cypress-realworld-app/blob/develop/cypress/plugins/index.ts
cypress/plugins/index.js
import axios from "axios";
import { percyHealthCheck } from "#percy/cypress/task";
import { bookingCancel } from "../../server/api/booking-controller";
export default (on, config) => {
on("task", {
percyHealthCheck,
async "booking:cancel"(user, bookingId, options) {
const response = await axios({
baseURL: Cypress.env("apiUrl"),
...bookingCancel(user, bookingId, options),
});
return response;
},
});
return config;
};
My errors:
Error: The plugins file is missing or invalid.
Your `pluginsFile` is set to `/cypress/plugins/index.js`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js`, `.ts`, or `.coffee` file.
Or you might have renamed the extension of your `pluginsFile`. If that's the case, restart the test runner.
Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.
at Object.get (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/errors.js:968:15)
at EventEmitter.<anonymous> (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/index.js:144:21)
at EventEmitter.emit (events.js:310:20)
at ChildProcess.<anonymous> (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:19:22)
at ChildProcess.emit (events.js:310:20)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
/cypress/plugins/index.js:1
import { percyHealthCheck } from "#percy/cypress/task";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1051:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
at runPlugins (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:213:15)
at Object.<anonymous> (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/index.js:8:25)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
NOTE: I verified that pluginsFile has the correct path and I even tried explicitly provide the path to the file and it didn't resolve the problem.

Looks like you might have a stray comma in your fourth to last line
});
return response;
}, <------------------ here
});
return config;
};

I got the same error, I had forgotten to execute the following code:
npm install --save-dev cypress-cucumber-preprocessor

Related

DateFormat.js SyntaxError: Unexpected token export

Using this with some Kubernetes PODS and one of the pods out of the blue gives me this error. It seems to come from the call on line 6. Have not changed anything was just doing a deployment on gitlab and noticed this POD said CrashLoopBackOff.
/app/config/auth.js line 6
var dateFormat = require('dateformat');
My nodemodules folder has the latest dateFormat.js from package.json
So not sure what the problem is. Does someone know how to fix it?
var token=/d{1,4}|D{3,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|W{1,2}|[LlopSZN]|"[^"]*"|'[^']*'/g;var timezone=/\b(?:[A-Z]{1,3}[A-Z][TC])(?:[-+]\d{4})?|((?:Australian )?(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time)\b/g;var timezoneClip=/[^-+\dA-Z]/g;export default function dateFormat(date,mask,utc,gmt){if(arguments.length===1&&typeof date==="string"&&!/\d/.test(date)){mask=date;date=undefined}date=date||date===0?date:new Date;if(!(date instanceof Date)){date=new Date(date)}if(isNaN(date)){throw TypeError("Invalid date")}mask=String(masks[mask]||mask||masks["default"]);var maskSlice=mask.slice(0,4);if(maskSlice==="UTC:"||maskSlice==="GMT:"){mask=mask.slice(4);utc=true;if(maskSlice==="GMT:"){gmt=true}}var _=function _(){return utc?"getUTC":"get"};var _d=function d(){return date[_()+"Date"]()};var D=function D(){return date[_()+"Day"]()};var _m=function m(){return date[_()+"Month"]()};var y=function y(){return date[_()+"FullYear"]
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:760:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Module.require (internal/modules/cjs/loader.js:723:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object.<anonymous> (/app/config/auth.js:6:18)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Module.require (internal/modules/cjs/loader.js:723:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object.<anonymous> (/app/config/passport.js:8:18)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)```
Was able to fix it by downloading an older version of dateformat. Nothing wrong with my code on the question its a simple problem with the library not the code come on.
Here I could make it work by using another version of this package,was working in the version 4.6.3, so I did:
npm i dateformat#4.6.3

Can't find module inside of my folder (discord.js)

As said in the title, I am using discord.js.
Shown below is the error I receive from my console when I try to run npm run start.
node:internal/modules/cjs/loader:922
throw err;
^
Error: Cannot find module './src/commands/clear.js'
Require stack:
- C:\Users\nicod\OneDrive\Desktop\CloudHostedBotCSCS\src\Bot.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:15)
at Function.Module._load (node:internal/modules/cjs/loader:763:27)
at Module.require (node:internal/modules/cjs/loader:991:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (C:\Users\nicod\OneDrive\Desktop\CloudHostedBotCSCS\src\Bot.js:7:15)
at Module._compile (node:internal/modules/cjs/loader:1102:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
at Module.load (node:internal/modules/cjs/loader:967:32)
at Function.Module._load (node:internal/modules/cjs/loader:807:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\nicod\\OneDrive\\Desktop\\CloudHostedBotCSCS\\src\\Bot.js'
]
}
A screenshot of the console will look like this:
Screenshot of console error
Here is the block of code with the problem:
const clear = require("./src/commands/clear.js");
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync("./src/commands/").filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./src/commands/${file}`);
client.commands.set(command.name, command);
}
The part with the problem is const commandFiles = fs.readdirSync('./src/commands/').filter(file => file.endsWith('.js'));. It keeps saying that the module for ./src/commands/ can't be found.
Here is a screenshot of my files: Screenshot of files + folders
No matter how much I tweak my code I still receive this error any ideas why?
Your error is in Bot.js file . that is in src directory.
then import should be require('./commands/clear.js') rather then require('./src/commands/clear.js').
Check directory tree.
instead of using fs.readdirSync('./src/commands/')
#Dario suggested using fs.readdirSync(__dirname+"/src/commands/"), but that still did not work. So I tweaked the code and fs.readdirSync(__dirname+"/commands/") ended up being the solution.

SyntaxError: Unexpected identifier Embed Message Discord.js

I´m trying to make a help command with Embed but dont works
/home/container/commands/other/help.js:15
const helpEmbed = new MessageEmbed()
^^^^^^^^^
SyntaxError: Unexpected identifier
at wrapSafe (internal/modules/cjs/loader.js:931:16)
at Module._compile (internal/modules/cjs/loader.js:979:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /home/container/node_modules/require-all/index.js:56:46
at Array.forEach (<anonymous>)
at requireAll (/home/container/node_modules/require-all/index.js:34:9)
This is the code
Basically you are using the Embed inside nothing. Your module.exports should look similiar to this:
module.exports = class extends Command {
constructor(...args) {
super(...args, {
description: 'Testing.',
category: "Information",
});
}
async run(message, args) {
const helpEmbed...
}
}
The code example above is from my command handler so yours could be a little different, but you need a start point like run or execute.

Module not found unless I use a complete path when creating plugins in Hapi

I'm trying to familiarise myself with HapiJS and have been playing around with it this week, I've run into a problem with plugins and paths. I get an error regarding the path I specify when I require a file. I can't use " ./ " without getting an error. The only way to overcome the error is to use the full complete path.
Here's my code that works:
'use strict';
const indexController = require('/Users/mylaptop/docker-node/controllers/IndexController.js');
module.exports.plugin = {
name: 'myPlugin',
version: '1.0.0',
register: async function (server, options) {
// Create a route for example
server.route({
method:'GET',
path:'/test',
handler: function (request, h) {
return indexController.loadIndex(h);
}
});
}
};
However, if I try to require my IndexController file this way:
const indexController = require('./controllers/IndexController.js');
Then I get this error:
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '/Users/mylaptop/docker-node/Users/mylaptop/docker-node/controllers/IndexController.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/mylaptop/docker-node/config/routes/index.js:5:25)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
It doesn't work inside of my plugin, yet outside of my plugin, requiring files this way works fine.
What could be the problem? How can I solve it?
Thanks in advance.
Problem solved with:
const indexController = require('../../controllers/IndexController.js');
My project root folder was 2 directories away, hence ../../ working for me.

How do I get html-snapshots to work?

I'm just trying to run html-snapshots. This should be easy, right?
This is what I started with:
npm install html-snapshots
That's all I need, right? Here's my snapshots.js file:
var htmlSnapshots = require('html-snapshots');
htmlSnapshots.run({
source: "sitemap.xml",
hostname: "localhost",
outputDir: "snapshots",
outputDirClean: true,
selector: "#results-widget"
});
And to run it:
node snapshots.js
But nooo:
module.js:340
throw err;
^
Error: Cannot find module '.\robots'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.module.exports.create (C:\webdev\node_modules\html-snapshots\lib\input-generators\index.js:38:16)
at Object.module.exports.run (C:\webdev\node_modules\html-snapshots\lib\html-snapshots.js:42:39)
at Object.<anonymous> (C:\webdev\snapshots.js:2:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
wtf?
Additional Info...
This is part of html-snapshots.js:
var inputFactory = require("./input-generators");
...
run: function(options, listener) {
...
var inputGenerator = inputFactory.create(options.input);
...
result = inputGenerator.run(options, (function(options, notifier){
Also, the html-snapshots\lib\input-generators folder contains the file robots.js
It looks like an issue inside html-snapshots\lib\input-generators\index.js file - it works fine on Linux systems but fails on Windows (path.sep has been used to build module name)
Problem is that it should load './robots' module instead of '.\robots'.
Quick fix is to update html-snapshots\lib\input-generators\index.js file - line 38.
Change line:
result = require(file);
to:
result = require(path.join(__dirname, file));
And it will work fine. I hope that will help.

Categories