gitbook init Error: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be - gitbook

node: v14.0.0
CLI version: 2.3.2
GitBook version: 3.2.3
Windows10
When execute gitbook init in an empty folder, it pops up:
$ gitbook init
warn: no summary file in this book
info: create SUMMARY.md
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Promise
And there is no "SUMMARY.md" created...
How could it be fixed?Thanks!

I have the same problem just as you. Switch back from latest node version to 12.18.1 LTS.
And everything gonna be ok.

Do you want to convert markdown files to an e-book? If so, pandoc is an alternative.
pandoc -o js_functional.epub --metadata title="Functional JavaScript"
*.md
If you want mobi format, calibre is a good converter.

npm install -g gitbook-summary
and cd to your target directory, run "book sm"
Summary will be resolved.

Related

Fix "kexec" error (failure, problem, broken) that prevents (unable to) "npm install" WebPack etc "node_modules" dir after node upgrade (node 12,13,14)

I upgraded "node" to "node 14", and ran an "npm install", but the install failed because of an error while attempting to compile "kexec" (a.k.a. "node-kexec"); which is required by "WebPack".
Error messages include:
npm ERR! path /Users/my_self/my_project/node_modules/kexec
...
npm ERR! In file included from ../src/kexec.cc:14:
npm ERR! In file included from ../../nan/nan.h:2884:
...etc...
npm ERR! ../src/kexec.cc:19:11: error: no member named 'Handle' in namespace 'v8'
...etc...
npm ERR! 1 warning and 9 errors generated.
npm ERR! make: *** [Release/obj.target/kexec/src/kexec.o] Error 1
npm ERR! gyp ERR! build error
...etc...
npm ERR! gyp ERR! not ok
This issue only shows up for projects that have a dependency upon "kexec". The actual purpose of "kexec" is to launch programs by passing a request to the OS, either directly or through a shell like "bash".
As it happens, WebPack depends upon "kexec". So to get WebPack working with "node" versions 12, 13, 14, etc, "kexec" has to compile.
This problem has already been documented and fixed on GitHub. In fact, there is a radically new version of "kexec" available, waiting for a "pull" to the master branch. The problem is that the "pull" has languished.
How can use the fixed version of "kexec" within my "npm install" to rebuild the "node_modules" directory as required by "WebPack"?
I was able to successfully get a revised version of "kexec" (a.k.a. "node-kexec") to compile via "npm install" despite an upgrade to "node" (node 14), the result being well built "node_modules" fulfilling requirements for "WebPack".
If using "npm" version "8.3.0" or higher, try using "overrides". See "Candidate Method 3", below. In my case, I didn't explore using "overrides" becasue I am using a version of "npm" that does not have the capability. Instead, I did some trickery.
The required version of "kexec" is 3.0.0, but that is old code which breaks when "node" is upgraded to or beyond "node" version 12.
An all new "kexec" 4.0.0 has been written. The re-write was available back in Oct 2020, but as of Jan 26, 2022, the revision is still languishing. The new code is awaiting a "pull" into the "master" branch. This v4.0.0 fixes the problem, except for the fact that "npm" can't find it.
"WebPack" requirements call for "kexec" v3.0.0; which is the broken version. It can't find v4.0.0 because it's not in the master branch. The obvious solution would be to convince "npm" to look elsewhere for "kexec". Some transparent override methods are described here. These methods involve modifying the "package.json" file; (hence, transparency). Later in this answer, I also describe a non-transparent method; this "trickery" is what worked for me.
Method 1 with package.json: Use "yarn" and "resolutions"
As per "tamlyn", Jul 15, 2020, "if you're using Yarn...[add] the following to your package.json:
"resolutions": {
"kexec": "meteor/node-kexec#update-for-node-12"
}
But this does not fit my situation, since I am using "npm", and not "yarn".
Method 2 with package.json: Use "npm" and "npm-force-resolutions"
There is a module "npm-force-resolutions" that attempts to make the above mentioned "resolutions" idea work with "npm". However, the word is that it works only with older versions of "npm".
Method 3 with package.json: Use "npm" and "overrides"
For "npm" version 8.3.0, there is a built in feature called "overrides" that is supposed to be the equivalent of "resolutions". Here is the documentation for it:
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
Presumably, the syntax for use would be like that shown above for "yarn", but with the word "overrrides" replacing "resolutions". If you are using a version of "npm" that is v8.3.0 or higher, you should try this. I did not explore this.
Non-Transparent Method
If possible, start by upgrading to the latest version of "npm".
$ sudo npm install -g npm#latest
And then check the "npm" and "node" versions. In my case, because several machines need to be coordinated, I did not have the absolute latest. Here is what I was working with:
$ npm --version
v7.12.0
$ node --version
v14.18.3
Having sufficiently upgraded "npm", you are ready to actually start fixing the "kexec" problem. If you have "npm" version 8.3.0 or more, try "Method 3", mentioned above. If that doesn't work, proceed as follows.
In this documentation, I will use the word "my_project_dir" to represent the directory in which you are trying to create your "node_modules" sub-directory. Start by going to that location.
$ cd my_project_dir
Move aside the existing "node_modules" directory (if any exists).
$ mv node_modules node-modules-old
You should now attempt a fresh install. Of course, this install will look at "package.json" or "package-lock.json", and know what is needed. However, presuming your development environment requires "kexec", and because the old "kexec" has trouble compiling within the new "node" environment, the install hits a wall; as shown here
$ npm install
...
make: *** [Release/obj.target/kexec/src/kexec.o] Error 1
... etc,
... etc, etc, more "build error" messages
In my case, I use "WebPack", which has a dependency on "kexec v3.0.0", which breaks when used with upgraded "node".
The totally new version of "kexec", which is the creation of a group of developers at "Meteor", is available on "github", directly through one of the developers, who goes by the user-name "StorytellerCZ". (See also list of URLs at end of this doc).
Use "git" to download the updated code. Actually, what I did was a "git clone" of the entire "node-kexec" module repository, as presented by "StorytellerCZ". This download has more than is needed, but that's ok.
$ pwd
/home/myself/my_project_dir
A "node_modules" sub-directory exists; it was created by the attempted "npm install". Descend into the sub-directory.
$ cd node_modules
$ git clone https://github.com/StorytellerCZ/node-kexec.git
This creates a sub-directory named "node-kexec"; which is a "git" repository. Note that the desired directory name is actually "kexec", but, for now, having two different names ("kexec" versus "node-kexec") will actually keeps things cleaner.
The next step depends upon whether a "kexec" directory already exists. Check for it.
$ ls -ld kexec
drwxr-xr-x 16 myself staff 512 Apr 30 2021 kexec
The "kexec" subdiretory might not exist; this depends upon what was left over from the failed "install"; (the "install" that got you looking for a fix in the first place). On my Mac OS X (BSD) system with "npm --version" of "7.12.0", the "kexec" remnant was preserved. On an AWS Linux system with "npm --version" of "6.14.15", the "kexec" directory was destroyed at every failed "npm install".
If the "kexec" directory exists, you just need to cherry-pick one file from the git clone. First move the old file asside; the following command moves the old file to a new name where-in "-2016" is a reminder of the year of the most recent "pull" of the source code for "kexec".
$ mv kexec/src/kexec.cc kexec/src/kexec-2016.cc
Now replace that with the desired version
$ cp -p node-kexec/src/kexec.cc kexec/src
And remove the clone, so that it doesn't cause problems at some later date.
$ rm -rf node-kexec
On the other hand, if "kexec" is not present as a subdirectory, then you must convert the "node-kexec" repository into a directory that is named "kexec".
$ mv node-kexec kexec
However, you probably need to do one more thing; a bit of subterfuge. The package dependencies for your project might include a requirement for exactly version "3.0.0" of "kexec"; this is the case for my project, which I assume is because of some dependancy of "WebPack". The "kexec" from "StorytellerCZ" is labeled as version "4.0.0"; (and indeed, it is an entirely new body of code). This is problematic, because, on some systems, "npm" will actually delete the subdirectory you just created, and replace it with the same old, bad "3.0.0" code. Therefore, some subterfuge is necessary.
To trick the "npm" system into accepting the new directory, edit the "package.json" file, and modify the value of the "version" parameter to "3.0.0". Yes, this really stinks, but it solves the immediate problem. (The real solution will be for the "4.0.0" changes to finally get integrated into the "master" branch.) The following steps make the change, cautiously.
Descend into pre-existing "kexec" directory, under "node_modules".
$ cd kexec
Make a copy of the file you are about to change. This leaves a clue for you, in the future, when you are wondering how the version number got the way it is.
$ cp -p package.json package.json-original
Edit the "package.json" file. For example, if your editor is "vim", you could invoke the editor like this:
$ vim package.json
Change the "version" value; make it "3.0.0". When that's done, save the edit and quit the editor.
Ascend out of the "kexec" sub-directory, back to "node_modules".
$ cd ..
So, at this point you have prepared a "kexec" module that should compile. You did it one of two ways: either (1) you had a pre-existing "kexec" directory and you simply copied over the updated "kexec.cc" file, or (2) you renamed "node-kexec" to "kexec" and you fiddled with the "version" number.
To re-try your install, first ascend out of the "node_modules" sub-directory, back to your project directory.
$ cd ..
Prove to yourself that this is the right place.
$ pwd
/home/myself/my-project-dir
Do the install.
$ npm install
The "kexec" error should be gone.
If you are still getting errors, check whether the very first line of warning message says the following:
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#1, but package-lock.json was generated for lockfileVersion#2. I'll try to do my best with it!
This warning should go away when you upgrade the "npm" version to 7.12.0 or better. Do so!
If "npm" protests about the presence of "git" information, that should go away once you upgrade the "npm" version to 7.12.0 or better. If the warning persists, then you can just get rid of the "git" info, as follows.
Descend into the repository dir
$ cd kexec # formerly named "node-kexec"
Confirm, just for fun, that the "git" structure is actually here. Note that "ls *" won't show hidden files, hence use this command:
$ ls -a | grep git
.git
.gitignore
Strip out the git repository information.
$ rm -rf .git
$ rm .gitignore
Ascend out of the "kexec" sub-directory, back to "node_modules".
$ cd ..
$ pwd
/home/myself/my-project-dir/node_modules
Retry the "npm install".
Appendix I
Here are some URLs to relevant github archives:
[https://github.com/jprichardson/node-kexec/issues/36][1]
[https://github.com/StorytellerCZ/node-kexec.git][1]
[https://github.com/meteor/node-kexec/tree/update-for-node-12][1]
Appendix II
On OS-X, the intermediate binary object file created during the build is:
node_modules/kexec/build/Release/obj.target/kexec/src/kexec.o
On OS-X, the executable appears to be:
node_modules/kexec/build/Release/kexec.node
On AWS Linux, I did not find either of those. I didn't bother to
seek an explanation, since WebPack had become functional, and
therefore my goal was achieved.

Node.js node:internal/modules/cjs/loader:936 error while trying to use discord.js

I'm trying to make a discord bot with the command prefix "*" but when I try to get the bot online/run it, it gives me this error:
node:internal/modules/cjs/loader:936
node:internal/modules/cjs/loader:936 throw err; ^
Error: Cannot find module 'C:\Users\name\const'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }
The module I'm using is discord.js and i've installed discord.js on CMD and the VSC terminal but it still comes up with the MODULE NOT FOUND error. I've looked around the internet and I can't find one that fixes the problem. I've tried reinstalling Node.js but it won't stop coming back. Please help, Thanks!
same error with me but I just change file dir cause I run node <filename.js> in the wrong dir so I just change like ---
the first step chacks you are in the right dir or not type: > ls
then if you are in the right dir then type: node <filename.js> if not then change your dir to change dir type: cd <filename>
and then run your first app or file for run type: node <filename.js>
I hope your error is solved!
you need to run it as an administrator so sudo(whatever you tryna run) as long as you are in the right directory
On Windows I solved it like this.
I went to the folder: C:\Users\Documents\AppData\Roaming\npm
And I deleted the file. create-react-app.
I started the project again, and it worked.
root cause, my path was messed up, but I only figured that out once I found where my npm packages where. I had thought they were in ../Programs/Roaming/npm etc but since an update (I think to node) my packages were actually in a Python Lib subdir.
Your Answer might be the same as mine, and I found out all this by using the
npm list -g
Command - which showed the globally installed packages, but also highlighted that this was nowhere to be found in my path
Hope this helps someone!
I had the same error and it was a case of trying to run the file in node from the wrong location.
My solution was to use the terminal and CD into the exact folder the file I was trying to run were and then after that I could run node filename.js.
In my case (this error ocurred at running docker container of next app), it was because I was running docker-compose without the flag --build, but of without copy lock files (package-lock.json and/or yarn.lock).
I updated my Dockerfile:
[...]
COPY yarn.lock .
RUN yarn install --frozen-lockfile
CMD [ "yarn", "dev" ]
And after, run with docker-compose up --build
When I was following a JS tutorial i got this error message too.
The problem was I copied an existing JS file and renamed it but it
through that error when i ran it.
When i created a new JS file, and copied the code in, and ran, it worked.
Before starting your server you need to make sure that the start file is mentioned below
cross-env NODE_ENV=production node index<start file name eg:index for index.js>
It happens when you run npm run start without getting into the project first... So, before starting to compile your project, run this command: cd <project folder name>...
It will stop showing the "Missing Module" Error and smoothly run your desired output in your browser
When was trying to find 'npm' & 'Rdme' path from command prompt to update the Rdme was getting this error Log
This error is caused when file can't be found or its a wrong path, In my case I added the missing file to respective folders- configured & updated in Environment variables (after adding missing files)
For the coming next. For me I'v got the error when I tried to run a package.json script with the npx run rather npm run.
In my case, I used chocolatey to install nodejs and it fixed my issue.
Open an Administrator Command Prompt (right click Command Prompt and select "Run as Administrator"), then run the following command:
choco install -y nodejs-lts
I hope it works for you too :)
The error tells that you've required packages that you haven't installed. So please make sure that you've installed every package that you've required in your bot. Also if you're sure that you've installed it, please check it again, there were namely some problems for some people that some of their packages got uninstalled while updating Discord.js to version 13.
For your problem in the comments ("TypeError [CLIENT_MISSING_INTENTS]"), it is now required in Discord.js version 13 to add your needed intents in the client. Please read this part of the Discord.js guide.
I fixed this issue by changing the opened directory of the terminal. Just go to the terminal and type: cd <folder name> until you reach the folder in which your js file is located. Then save and run again.
npm uninstall webpack-cli -D
npm install webpack-cli#3.3.12 --save-dev
than work fine

How can i solve Geojson to shapefile conversion error?

I'm trying to convert geojson file to shapefile. I'm using the geojson2shape method but when I run code below I receive this error. I also install ogr2ogr via npm install ogr2ogr but I have the error. How can I solve this error?
var geojson2shape = require('geojson2shape')
// a shapefile is actually multiple files. geojson2shape will output a zipped version if specified.
var zip = true
geojson2shape(__dirname+'/polygon.geojson', __dirname+'/polygon.shp',zip, function(err){
if(err) throw err
console.log('success');
})
Command failed: ogr2ogr -f "ESRI Shapefile" C:\upload2/output/out.shp C:\upload2/Files/imgUploader_1577252750283_AC127138-5645-497D-AF51-3F4EA12E20C5.geojson -overwrite -lco ENCODING=UTF-8
'ogr2ogr' is not recognized as an internal or external command
ogr2ogr is a "native application". The package in npm called ogr2ggr is just a kind of wrapper around the native tool, as it explains in the doc:
ogr2ogr requires the command line tool ogr2ogr - gdal install page. We recommended using the latest stable version.
So to use geojson2shape or even npm's ogr2ogr follow the instructions for installing gdal/ogr2ogr in your system, and make sure that ogr2ogr binary is on the PATH

babel + path + node 6.x: TypeError: Path must be a string. Received undefined

I've been trying to update my nodejs version to 6.x but the following errors always appear everytime:
path.js:7
throw new TypeError('Path must be a string. Received ' + inspect(path));
^
TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.dirname (path.js:1326:5)
at /usr/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:374:36
at /usr/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:396:22
at Array.map (native)
at OptionManager.resolvePresets (/usr/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:385:20)
at OptionManager.mergePresets (/usr/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:369:10)
at OptionManager.mergeOptions (/usr/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328:14)
at /usr/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:370:14
at /usr/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:390:24
I tried with those three version:
nodejs-6.0.0-1
nodejs-6.2.0-1
nodejs-6.2.1-1
in package.json:
"babel-core": "^6.9.1"
I quite lost about where to start looking to debug. Anybody has a suggestion ? :) More info would be relevent ? Let me know !
Thanks in advance !
The issue has something to do with Node 6. Using Node 5.x instead will probably fix the issue for you, if that's an option.
The easiest way to do this is to install Node Version Manager (or a port for Windows), then run these commands:
nvm install 5
nvm use 5
If you want to use 5.x as your default node version, run this command:
nvm alias default 5
upgrade babel-core to 6.10.4..

Unable to install nodejs on my computer

I am using windows and when I took reference to download node js from here. When I write this line
C:> cinst nodejs.install -Version 0.6.10
in CMD it gives an error
C:>cinst nodejs.install -Version 0.6.10
'cinst' is not recognized as an internal or external command,
operable program or batch file.
I don't know how to install node js.I also have a question that if I install node js version say v0.10.26 will the programs made with previous versions(say 0.9) will work on 0.10
That error means that your cmd session can't find cinst. To use cinst, you have to install the package manager from http://chocolatey.org/
If you just want to get Node.js running though, there's a Windows installer at http://nodejs.org/download/ or you can just hit the big green Install button at http://nodejs.org/
Summarizing comments:
All of the versions are maintained and available under http://nodejs.org/dist/, 0.6.10 can be found at: http://nodejs.org/dist/v0.6.10/ and you can get the Windows installer by downloading the .msi file.
As for whether there might be breaking changes from version to version, most code moves forward just fine, but testing is always a good idea. Some packages will specify a specific version in their package.json file, but most will just request a version greater than a certain point in the engines element like:
{ "engines" : { "node" : ">=0.6.10" } }

Resources