Creating a migration in knex.js is throwing an error - node.js

I am trying to create a migration and it throws the following error
yarn run v1.6.0
(node:14212) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usabil
ity issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods in
stead.
$ babel-node node_modules/.bin/knex migrate:make create_linky_table
C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (C:\Users\Sagar\Desktop\linky\lms-linky\api\node_modules\pi
rates\lib\index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I have the following set up in my script in package.json
"knex": "babel-node --require ./node_modules/dotenv/config node_modules/.bin/knex --knexfile='src/knexfile.js'",
I am using the following code to create the migration
yarn knex make:migration create_linky_table
I am currently using windows and i came upon this answer . Could it be a windows issue?

What #Mikael Lepistö said is correct.
I faced similar issue while doing migration scripts on windows.
My previous command was:
babel-node node_modules/.bin/knex --knexfile src/database/knexfile.js migrate:latest
I changed it to:
babel-node node_modules/knex/bin/cli.js --knexfile src/database/knexfile.js migrate:latest
And the error has gone. May be changing the reference from .bin/knex to /knex/bin/cli.js will make the magic for youso give it a try

Sounds like C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex script in windows is not JavaScript executable, but actually shell script wrapper in Windows. So when you try to use babel-node or node to execute it, node interpreter fails because you are trying to run bash/sh shell script with it.
Check out what is stored inside the C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex script and if there is a way to override, which node interpreter is used, you can override it with babel-node. If there is no way to override it, you can just check out if it calls for example node_modules/knex/bin/cli.js and call directly that with babel-node.
I would check those out myself, but I don't have Windows node tools setup on this desktop.

Related

Getting an error when running "npx wdio config"

I get the following error when I try to set up "Hello World" test suite into my project by running: "npx wdio config". I followed the instructions on the https://webdriver.io/docs/gettingstarted and still not able to get it to work.
Can someone help me with resolving this:
WDIO Configuration Helper
? Where is your automation backend located? (Use arrow keys)
❯ On my local machine
In the cloud using Experitest
In the cloud using Sauce Labs
In the cloud using Browserstack or Testingbot or LambdaTest or a different service
I have my own Selenium cloud (node:2831) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'find' of undefined
at Object.run (/Users/gustavosuarez/web/mo-appium-wdio-jasmine/node_modules/#wdio/cli/build/index.js:67:19)
at Object.<anonymous> (/Users/gustavosuarez/web/mo-appium-wdio-jasmine/node_modules/#wdio/cli/bin/wdio.js:11:21)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Seems to be a problem with the latest version of the #wdio/cli dependency. I solved the problem by using an older version and it works now ("#wdio/cli": "7.3.1"). Just add that dependency to your package.json and run yarn or npm install again, then npx wdio config and it should work.

How to run an existed language server without vscode

I am trying to develop my own IDE with language server protocol support, so i download language server written in typescript and try to start them with Node.js.
First, I packaged the server package with webpack. and then start with the command "node server.js", server.js is produced by webpack. but I got
Error: Connection input stream is not set. Use arguments of createConnection or set command line parameters: '--node-ipc', '--stdio' or '--socket={number}'
at D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:172642
at t.createConnection (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:179222)
at Object.999 (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:72865)
at n (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:186299)
at D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:186653
at Object.<anonymous> (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:186661)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
then I followed the Error information, replaced the command with "node server.js --node-ipc". the error above didn't appear again, but i didn't got a server process in my Windows task manager.
I am new to typescript and language-server-protocol, did I got sth wrong or misunderstand sth?

Erorr running node.js project after moving to a new development machine: [!] SyntaxError: Unexpected token { in rollup.config.js

I have a working node.js development environment created with Anaconda. When I have moved the project to another machine, re-created identical environment, I get error when running npm run build (or npm run dev):
[!] SyntaxError: Unexpected token {
c:\test\myproject\rollup.config.js:1
(function (exports, require, module, __filename, __dirname) { import { nodeResolve } from '#rollup/plugin-node-resolve'
^
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.require.extensions.(anonymous function) [as .js] (c:\test\myproject\node_modules\rollup\dist\shared\loadConfigFile.js:560:13)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
This is the top line of my rollup.config.js where the error occurs:
import { nodeResolve } from '#rollup/plugin-node-resolve'
Node version: v10.13.0.
I have compared npm modules installed on both machines, they are identical, with identical versions. I'm truly puzzled. I'll be grateful for any pointers where to look for differences between the two machines and how to make the project working. I've already spent half a day looking at it and I've run out of ideas.
UPDATE:
I copied the whole conda environment to the new machine to mirror the working configuration on the old machine but the error still persists. So now I have identical environments, identical source code but it works on one machine and it doesn't on another.
It turns out rollup doesn't work properly when the project path goes through an NTFS directory junction.
Sample layout:
C:\Home - directory
\Work - directory
\MyProject - directory
C:\Work - junction to C:\Home\Work
Results:
cd C:\Work\MyProject
npm run build
.... results in error
cd C:\Home\Work\MyProject
npm run build
.... everything works OK

Run a node package via node

I am trying to run a node package.
Technically, I can simply do ./node_modules/.bin/<package name> from my project's root folder, or even npx <package name> from any folder.
But I need to run node with a specific configuration of max-old-space-size set to 4096.
I am therefore trying to invoke it as follows:
node --max-old-space-size=4096 ./node_modules/.bin/<package name>
Which gives me the following error:
<root folder>\node_modules\.bin\<package name>:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I am pretty sure that this problem is due to the fact that I am running on Windows.
I did some research and came across this GitHub thread, which makes me even more confident that the problem is OS-related.
But I haven't been quite able to find a workable solution within this thread.
The only clue that I have found is by sc0ttwad3 from 12 days ago, suggesting to change this:
./node_modules/.bin/<package name>
To this:
./node_modules/<package name>/bin/<package name>.js
But there is no such js file in this path (in fact, there is not even a bin folder in this path).
Can anyone shed some light on this?

How do I enable --debug for node.js when running GeddyJS

GeddyJS is started by running geddy from the root of the project.
I'm having some trouble getting GeddyJS to run under node.js with debug enabled.
getty installs /usr/local/bin/geddy:
#!/usr/bin/env node
...
which I made a quick copy of, and amended the shebang line:
#!/usr/bin/env node --debug
...
but that does not work, because env can't find 'node --debug'.
I then tried to write a wrapper script to act as the interpreter in the shebang line here:
#!/bin/sh
exec /usr/bin/env node --debug $#
And this time, node is started with a debugger enabled, but the paths must be messed up, or environment must be different, because I am getting missing module exceptions:
$ geddy-debug
debugger listening on port 5858
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module '../lib/geddy'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (/usr/local/bin/geddy-debug:4:1)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
This of course works fine if I don't try to enable debugging.
I want to debug in eclipse as per : https://github.com/joyent/node/wiki/Using-Eclipse-as-Node-Applications-Debugger, which works great with just node --debug scriptname.js
Any suggestions are appreciated.
Answering my own question, so others can benefit if they happen to see this:
From the project directory, override the shebang line and invoke the interpreter directly to run the geddy script:
/usr/bin/env node --debug /usr/local/bin/geddy
There's a Debugging Geddy WikiPage with a bit more info.

Resources