Error importing dependency in Cypress Cucumber - javascript

I have a problem when importing some dependencies in Cucumber. The error is the following:
Running: features\my_feature.feature... (1 of 1)
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
Oops...we found an error preparing this test file:
cypress\integration\features\my_feature.feature
The error was:
Error: Cannot find module 'C:gitdevelopPROJECT
ode_modulescypress-cucumber-preprocessorlib/resolveStepDefinition' from 'C:\git\develop\PROJECT\cypress\integration\features'
This occurred while Cypress was compiling and bundling your test code. This is usually caused by:
- A missing file or dependency
- A syntax error in the file or one of its dependencies
Fix the error in your code and re-run your tests.
I'm not able to run the features I worked on because of this. I suppose the key for the error is in line 3. I'll explain this, the path of the file is the following: C:\git\develop\PROJECT\cypress\node_modules\cypress-cucumber-preprocessor\lib\resolveStepDefinition, but the library is recognizing the \n substring from \node_modules as a break line and is not recognizing the \ in the path. I don't know if that makes any sense.
I don't know what to publish here, because I don't think it's related to a configuration or anything like that. If you have any idea or need anything else, please, tell me. I'll publish all that could be required.

Make sure your file structure is like:
cypress/integration/myfeatures/feature1.feature
cypress/integration/myfeatures/feature1/feature1.js
This structure is required by cypress-cucumber-preprocessor and might be why you get the resolveStepDefinition error message. See the github docs
I believe the error message you get is misleading you in thinking the '\n' is an issue in the code, but in reality, it's the console that can't properly handle the '\n'.

Related

nuxt fails with an error not being able to parse source for import analysis

When I attempt to make the server, it throws up a 500 error and the following error is shown in the terminal:
[SSR] Error transforming virtual:C:/Users/User/Documents/CODING/Ted's/.nuxt/plugins/server.mjs: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
I've attempted to run npm cache clean --force
I've reinstalled npm numerous times, given Everyone full privs for the dir it is in, ran VSCode as admin, I'm out of ideas.
The problem is most certainly related to those issues:
github/nuxt: incompatible with paths with ' in the filename #2192
github/nuxt: fix: escape dynamic import paths #4286
This PR addresses issues when using rollup for a project with ' in the path, for example /Users/Daniel's Projects/project/. Although normal imports are escaped correctly, it seems that dynamic imports are treated differently and we need to escape them as well.
Your path C:/Users/User/Documents/CODING/Ted's/ contains a ' and according to the issue this results in that problem.
So the solution to the problem is to get rid of that ' in your path, or wait until a version of nuxt is released that fixes that problem.
given Everyone full privs for the dir it is in, ran VSCode as admin, I'm out of ideas.
That is something you should never do. There are only really rare cases where you probably might need that, and even then you should rethink that multiple times. Running VSCode as admin would allow vscode and all its installed plugins to mess around with a large amount of the system. If you do that you need to fully trust all of those.

What it means "require is not defined" in JS and how the libraries are available for the browser?

I installed through npm in WebStorm this library
npm install basicscroll
The IDE highlights the words of the package, and everything seems fine until I try to see the project in the browser:
The console gives me this issue:
applicative.js:15 Uncaught ReferenceError: basicScroll is not defined
at applicative.js:15
at NodeList.forEach (<anonymous>)
at applicative.js:6
So I added at the beginning of my JS file this statement:
const basicScroll = require('basicscroll')
The result this time is that the library remains highlighted, but the method called on it not. And in browser this is the error prompt by the console:
Uncaught ReferenceError: require is not defined
I checked my node_modules directory, I can see the sub-directory, so I think the installation process went right. I also checked the package.json file:
"dependencies": {
"basicscroll": "^3.0.2",
[...]
I honestly don't know where the problem is. I'm new to web development and online I found that the webpack module-bounder could help me, but I don't even know where to start. What is wrong ?
Thank'you !
It seems like you are trying to use server-side code in a client-side environment. As far as I know require is a NodeJS thing and doesn't exist in the browser.
Your easiest solution would be to use a <script> tag in your html to import the files you need. Something like <script src="dist/basicScroll.min.js"></script>
This answer mentions some other tools you could use to manage that sort of thing: https://stackoverflow.com/a/19059825/1801137

does not provide an export named 'BrowserQRCodeReader'

I am using zxing-js/library library for qr code reading. I am facing a strange issue. The code for the qr scanning works in stackblitz online sample code, but not in my local environment.
I am getting this error in local environment on run time. The compilation proceeds successfully.
Uncaught SyntaxError: The requested module '/node_modules/#zxing/library/esm5/index.js' does not provide an export named 'BrowserQRCodeReader'
stackblitz link
github link
It seems like the zxing-js/library has issues with bundling.
I can reproduce the error by running npm run build, followed by npm run start.
Looks like some bundling would be required for you to get this working in the browser. See this post for more info
In the meantime, you can use npm run start:dev, and you will be able to do local development as expected.
Thanks #passle_ from the #open-wc team for helping with this.
In addition to jlengrands answer, npm start will start the owc-dev-server which does a minimal amount of work; it'll only resolve the bare modules.
The QR code library that you're trying to use uses commonjs, it'll need a little magic to be transformed so the browser can understand that code. The webpack-dev-server can do this for you, which you can run with npm run start:dev.

No console.log to STDOUT when running "npm test" (jest)

From what I know console.log() should work without problem printing to the STDOUT of my console, when running a script.
But in my case I have NPM configured to run Jest when issuing npm test from the shell, and any console.log() inside the test files doesn't print anything on the screen.
I tried also to use process.stdout.write() but still I get no custom output when running npm test.
How am I supposed to debug stuff in my test scripts?
I can't figure out if it is a problem from Node, from NPM, or from Jest.
There's a Jest issue that looks similar to mine but still I cannot solve and get to output a simple string; while there rest of Jest output is echoed as usual.
Anybody experienced a similar problem?
EDIT 1:
I tried running npm test -- --runInBand but the log doesn't appear.
Note
trying to run the command repeatedly like
console.log('foo...');console.log('bar..');console.log('baz..');
I can sometimes see the log, but this is then overwritten/hidden by the rest of the following Jest output.
From the linked issue since the problem is going on since years...
There is a pull request in the alpha release that is going to fix this problem. Looks like the last refining is being worked in the past few hours (see Github issue link).
However I found a solution that works for my simplest case:
just run enabling verbose mode and the log will magically appear!
npm test -- --verbose=true
This will not fix in every case; maybe async/multi-thread/etc will still have problems (please report your experiences, so I can update the answer); fo r example adding a process.exit(1) after the log will hide it again.
Trying to press ctrl + c before the process.exit() runs (with the right timing...) will show that the log is actually there and being overridden.
I will update the answer with news, but probably this will help others in starting with Node/NPM/Jest setups!
Jest's GitHub issue mention some useful details/suggestions:
https://github.com/facebook/jest/issues/2441#issuecomment-713433790
https://github.com/facebook/jest/issues/2441#issuecomment-724131782
https://github.com/facebook/jest/issues/2441#issuecomment-586359238
https://github.com/facebook/jest/issues/2441#issuecomment-611122871
https://github.com/facebook/jest/issues/2441#issuecomment-623856169
aaaand.... https://github.com/facebook/jest/issues/2441#issuecomment-649391333
Jest replaces the global console module; this apparently is the source of the issue. And also the fact that Jest will set it to true automatically if you're running a single test. upside_down_face
This isn't clean, but I've had luck with it, hopefully it'll help you until a fix is published: log some extra newlines after the log that's getting overwritten:
console.log('I want to be seen!');
console.log('\n\n\n\n');
I had this issue and it turns out that in my case, the problem was calling process.exit(1) immediately after writing to the console. When you do this during Jest tests, the output seems to be lost.
The (not-entirely-satisfying) workaround that I settled on is:
console.warn('stuff I want to write to the console');
if (process.env.NODE_ENV === 'test') {
setTimeout(() => process.exit(1), 1000);
} else {
process.exit(1);
}
For this, the NODE_ENV environment variable would need to be set to test in your Jest setup script or elsewhere.

Parse deploy of cloud code failing with message "Update failed with internal error"

I've been running Parse cloud code for a few months using CLI version 1.4.1 with no problems. I just updated using the CLI to the latest version, 1.4.2, but now when I deploy I get this output:
Uploading source files
Finished uploading files
Update failed with internal error
I've checked for the one problem I see documented elsewhere, which is erroneous quotes around some parse classes like Parse.User and Parse.Installation. It doesn't look like these are my problem.
Is there any way to find out more about the error, besides trial and error with my several thousand lines of code? :)
Upon upload attempt, Parse is parsing your code (pun intended :-) checking for errors, and deployment fails if any errors found.
One possibility is to check Logs (in your Dashboard under Core/Logs), also the Error submenu of Logs.
Another is to run the command parse develop your_app and see all the errors in your terminal.
For a large code, you probably want to write some unit tests if you aren't doing this already.

Categories

Resources