Uncaught Error: Cannot find module './charset.js' - javascript

Why am I getting this error?
Uncaught Error: Cannot find module './charset.js'
package.json
{
"name": "app",
"version": "1.0.0",
"description": "Application built with Flux and React.js",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Joe Collins",
"license": "",
"devDependencies": {
"browserify": "*",
"flux": "*",
"gulp": "*",
"reactify": "*",
"vinyl-source-stream": "*",
"object-assign": "*"
},
"dependencies": {
"bufferutil": "^1.2.1",
"charset": "^1.0.0",
"http": "0.0.0",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"socket.io": "^1.4.5",
"utf-8-validate": "^1.2.1"
}
}
gulpfile.js
var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');
var source = require('vinyl-source-stream');
gulp.task('browserify', function() {
browserify('./src/js/main.js')
.transform('reactify')
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('dist/js'))
});
gulp.task('copy', function() {
gulp.src('src/index.html')
.pipe(gulp.dest('dist'));
gulp.src('src/css/*.*')
.pipe(gulp.dest('dist/css'));
gulp.src('src/js/vendors/*.*')
.pipe(gulp.dest('dist/js'));
});
gulp.task('default', ['browserify', 'copy'], function() {
return gulp.watch('src/**/*.*', ['browserify', 'copy']);
});
App.js
var io = require('socket.io')();

You have to use socket.io-client for client side stuff. I have a hunch that charset.js uses a binary, or something that can't be converted to the browser.
https://github.com/socketio/socket.io-client

I was facing same problem but with some other module I did reinstall with latest and it is working for me
Problem
Error: Cannot find module './charset.js'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (module.js:534:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1269:46)
at Function.Module._load (module.js:464:25)
at Module.require (module.js:577:17)
at Module.require (pkg/prelude/bootstrap.js:1153:31)
at require (internal/module.js:11:18)
at /snapshot/html/config/configurator-file-api/node_modules/accepts/node_modules/negotiator/lib/negotiator.js:21:16
at Array.forEach (<anonymous>)
at Object.<anonymous> (/snapshot/html/config/configurator-file-api/node_modules/accepts/node_modules/negotiator/lib/negotiator.js:19:18)
at Module._compile (pkg/prelude/bootstrap.js:1243:22)
at Object.Module._extensions..js (module.js:644:10)
at Module.load (module.js:552:32)
at tryModuleLoad (module.js:495:12)
at Function.Module._load (module.js:487:3)
at Module.require (module.js:577:17)
at Module.require (pkg/prelude/bootstrap.js:1153:31)
Solution
cd /var/html/config/configurator-file-api/node_modules/accepts/
npm uninstall negotiator --save
npm install negotiator --save
Yes it is working

Related

How to fix "cannot find module'./node'' while compiling with pkg

the nodejs script works when I do node main.js but when I compile it into an executable with pkg it gives me this error :
pkg/prelude/bootstrap.js:1876
throw error;
^
Error: Cannot find module './node'
Require stack:
C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js
C:\snapshot\project\node_modules\hookcord\src\fire.js
C:\snapshot\project\node_modules\hookcord\src\index.js
C:\snapshot\project\node_modules\hookcord\index.js
C:\snapshot\project\main.js
If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js:3:19)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js',
'C:\snapshot\project\node_modules\hookcord\src\fire.js',
'C:\snapshot\project\node_modules\hookcord\src\index.js',
'C:\snapshot\project\node_modules\hookcord\index.js',
'C:\snapshot\project\main.js'
],
pkg: true
}
I have a similar error while packaging a NestJS application.
Here is my package.json file
{
"bin": "dist/main.js",
"pkg": {
"assets": [
"node_modules/**/*"
],
"outputPath": "bin",
"scripts": "dist/**/*.js",
"targets": [
"node14-linux-x64",
"node14-macos-x64"
]
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"build2": "pkg package.json",
"start": "nest start --watch",
"start:dev": "nest start --watch",
"start:prod": "node dist/main",
},
"dependencies": {
"#nestjs/common": "^7.0.0",
"#nestjs/core": "^7.0.0",
"#nestjs/platform-express": "^7.0.0",
"#nestjs/schedule": "^0.4.3",
"#nestjs/typeorm": "^7.1.4",
"#sentry/node": "^6.7.2",
"#sentry/tracing": "^6.7.2",
"axios": "^0.21.1",
"class-validator": "^0.12.2",
"fast-speedtest-api": "^0.3.2",
"jsonpath": "^1.1.0",
"moment": "^2.29.1",
"mysql": "^2.18.1",
"mysql2": "^2.2.5",
"querystring": "^0.2.1",
"queue-system": "^3.0.2",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"typeorm": "^0.2.27",
"winston": "^3.3.3",
"xml-js": "^1.6.11",
"xml2json": "^0.12.0"
},
"devDependencies": {
"#nestjs/cli": "^7.0.0",
"#nestjs/schematics": "^7.0.0",
"#nestjs/testing": "^7.0.0",
"#types/express": "^4.17.3",
"#types/node": "^13.9.1",
"#typescript-eslint/eslint-plugin": "3.9.1",
"#typescript-eslint/parser": "3.9.1",
"eslint": "7.7.0",
"eslint-plugin-import": "^2.20.1",
"ts-loader": "^6.2.1",
"ts-node": "9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
}
}
The command I am running is: pkg package.json and it seems to run without any error. However, when running the binary I have similar errors:
error: Error: Cannot find module 'esprima'
Require stack:
- aesprim
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Function.resolve (internal/modules/cjs/helpers.js:107:19)
at Object.<anonymous> (/snapshot/app/node_modules/jsonpath/lib/aesprim.js:4:20)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.<anonymous> (/snapshot/app/node_modules/jsonpath/lib/aesprim.js:15:11)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'aesprim' ],
pkg: true
},
I tried to install esprima manually and create the package again, but the error is the same.
Thanks for your help

I have faced this Error: Cannot find module 'webpack-cli/bin/config-yargs' when I command `npm start`

I have faced problem when I command npm start and it throws errror
$ npm start
> chapter_15_2#1.0.0 start E:\js\stack-learner\chapter_15_2
> webpack-dev-server
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- E:\Js\Stack-Learner\chapter_15_2\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (E:\Js\Stack-Learner\chapter_15_2\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
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) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'E:\\Js\\Stack-Learner\\chapter_15_2\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! chapter_15_2#1.0.0 start: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the chapter_15_2#1.0.0 start 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! C:\Users\neloy\AppData\Roaming\npm-cache\_logs\2021-02-18T06_10_09_676Z-debug.log
code of Package.json .
{
"name": "chapter_15_2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.12.16",
"#babel/core": "^7.12.16",
"#babel/node": "^7.12.16",
"#babel/polyfill": "^7.12.1",
"#babel/preset-env": "^7.12.16",
"#babel/register": "^7.12.13",
"babel-loader": "^8.2.2",
"babel-register": "^6.26.0",
"html-webpack-plugin": "^5.1.0",
"webpack": "^5.22.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
}
}
Code of webpack.config.js
const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
require('babel-register')
module.exports = {
entry: ['#babel/polyfill', './src/app.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module:{
rules:[
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
plugins: [
new htmlWebpackPlugin({
template: "./index.html"
})
],
mode: 'development',
devtool: 'inline-sourse-map',
devServer:{
open: true,
contentBase: './dist'
}
}
You need to use npm#6
It's temporary compatibility issue, caused by npm#7 (it was released less then month ago)
Just use 6 branch and everything will work for now.

Webpack - npm run start and build doesn't work?

I am used to create react projects using create-react-app but i decided to create one without it but i am stuck in webpack configuration as i am new to it:
This is my package.json file:
{
"name": "package.json",
"version": "1.0.0",
"description": "Demo",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production"
},
"author": "",
"license": "MIT",
"dependencies": {
"#babel/core": "^7.12.3",
"#babel/preset-env": "^7.12.1",
"#babel/preset-react": "^7.12.1",
"babel-loader": "^8.1.0",
"css-loader": "^5.0.0",
"html-webpack-plugin": "^4.5.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"server": "^1.0.30",
"style-loader": "^2.0.0",
"webpack": "^5.2.0",
"webpack-cli": "^4.1.0",
"webpack-dev-server": "^3.11.0"
}
}
webpack.config.js file:
const path = require('path');
const HTMLplugin = require('html-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const rules = [
{
test: /\.js$/,
exclude: /node-modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
exclude: /node-modules/,
use: ['style-loader', 'css-loader']
}
]
module.exports = {
entry: path.join(__dirname, 'src', index.js),
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, '/build')
},
module: {rules},
plugins: [
new HtmlWebpackPlugin({template: './public/index.html'})
]
}
.babelrc.json file:
{
"presets": ["#babel/preset-env","#babel/preset-react"]
}
this is my whole project folders and files tree:
When i run npm run start or npm run build, it fails:
with npm run start, i get this error:
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- C:\Users\saher\Desktop\New folder\node_modules\webpack-dev-server\bin\webpack-dev-server.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 require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\saher\Desktop\New folder\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
With npm run build:
[webpack-cli] ReferenceError: index is not defined
I am new to webpack and i can't figure out where the problem is, i think i have installed all files and configurations required to make it work, so where is the problem exactly??
I think the problem is, you wrote index without string quotes.
entry: path.join(__dirname, 'src', index.js)
This should be
entry: path.join(__dirname, 'src', 'index.js')
It is like a variable when you write without string quotes. You can try the same this on console.log.
Because index is not defined.
There is an open bug report stating webpack-server 3.11 is not compatible with with webpack-cli v4.
The report can be found here: Issue 2759
Yes - webpack-dev-server does not work with webpack-cli v4
Link to comment: https://github.com/webpack/webpack-dev-server/issues/2759#issuecomment-706668920
The solution is to revamp your project.json file by changing to compatible versions (and welcome to Webpack :-) )
"main": "index.js" in package.json should be "main" : "src/index.js"

Task runner explorer VS2019 v16.6.2 failed to load Gulpfile.js

Here is the output error window result below.
Failed to run "D:\TortSVN\Oil Diversity\Main Web App\LatsetOildiversity\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
fs.js:27
const { Math, Object } = primordials;
^
ReferenceError: primordials is not defined
at fs.js:27:26
at req_ (D:\TortSVN\Oil Diversity\Main Web App\LatsetOildiversity\node_modules\natives\index.js:143:24)
at Object.req [as require] (D:\TortSVN\Oil Diversity\Main Web App\LatsetOildiversity\node_modules\natives\index.js:55:10)
at Object.<anonymous> (D:\TortSVN\Oil Diversity\Main Web App\LatsetOildiversity\node_modules\graceful-fs\fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
Only showed a part of the error here above. Here is my version for npm and gulp below.
PM> npm -v
6.14.4
PM> gulp -v
CLI version: 2.3.0
Local version: 4.0.2
PM>
Here is my package.json content below.
{
"name": "odg",
"version": "1.0.0",
"description": "OD",
"main": "app/main.js",
"keywords": [],
"author": "Mohammad MalekMakan",
"private": true,
"devDependencies": {
"grunt": "^1.0.3",
"gulp": "3.9.0",
"gulp-concat": "^2.5.2",
"gulp-connect": "^5.0.0",
"gulp-durandal": "^1.1.7",
"gulp-jshint": "^2.0.4",
"gulp-less": "^3.0.2",
"gulp-livereload": "^3.8.0",
"gulp-minify": "0.0.14",
"gulp-minify-css": "^1.0.0",
"gulp-server-livereload": "^1.2.1",
"gulp-sourcemaps": "^1.5.1",
"gulp-util": "3.0.4",
"jshint": "^2.9.4",
"jshint-stylish": "^2.2.1",
"mout": "~1.0.0"
},
"dependencies": {
"grunt-cli": "1.2.0",
"natives": "^1.1.6"
}
}
Here is the content of gulp.js file.
/// <binding Clean='build' />
var gulp = require('gulp');
var connect = require('gulp-connect');
var concat = require('gulp-concat');
var durandal = require('gulp-durandal');
var jshint = require('gulp-jshint');
var less = require('gulp-less');
var minifyCSS = require('gulp-minify-css');
var path = require('path');
var server = require('gulp-server-livereload');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('copy', function() {
gulp.src('auth-complete*')
.pipe(gulp.dest('dist'));
});
gulp.task('js-watcher', function() {
gulp.src('./app/**/*.js')
.pipe(connect.reload());
});
gulp.task('less-watcher', function() {
gulp.src('./styles/**/*.less')
.pipe(connect.reload());
});
gulp.task('html-watcher', function() {
gulp.src('./app/**/*.html')
.pipe(connect.reload());
});
gulp.task('watch-all', ['analyze'], function(){
gulp.watch(['./app/**/*.html'], ['html-watcher']);
gulp.watch(['./app/**/*.js'], ['analyze', 'js-watcher']);
gulp.watch(['./styles/**/*.less'], ['less', 'less-watcher']);
});
gulp.task('default', [ 'analyze', 'less', 'connect', 'watch-all']);
gulp.task('build', ['analyze', 'less', 'durandal', 'copy']);
As i have searched plenty of solutions like this Gulpfile.js failed to load and this https://developercommunity.visualstudio.com/content/problem/961170/gulpfile-fails-to-load-after-upgrading-to-vs2019-1.html but nothing worked for me.
Found the solution it's not working on VS2019 v16.6.2 but instead, it's working on VS2017 as i installed lower series. Here is a screenshot below

Node.js - "Cannot find module 'module.js' "

I'm using Heroku and I get this error..
2016-10-10T03:34:11.188366+00:00 app[web.1]: Error: Cannot find module 'module1.js'
2016-10-10T03:34:11.188369+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:339:15)
2016-10-10T03:34:11.188370+00:00 app[web.1]: at Function.Module._load (module.js:290:25)
2016-10-10T03:34:11.188371+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-10-10T03:34:11.188371+00:00 app[web.1]: at require (internal/module.js:20:19)
2016-10-10T03:34:11.188372+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:42:15)
2016-10-10T03:34:11.188373+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-10-10T03:34:11.188374+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-10-10T03:34:11.188374+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-10-10T03:34:11.188375+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-10-10T03:34:11.188375+00:00 app[web.1]: at Function.Module.runMain (module.js:447:10)
app.js
/**CUSTOM_MODULES**/
var module1 = require('module1.js');
/**MODULES_END**/
module1.js
function module1(){
//My code
}
module.exports = module1;
module1.js is in the same directory as my app.js.
I have tried countless things but nothing seems to work.
I have tried:
var module1 = require('module1.js');
var module1 = require('./module1.js');
var module1 = require('../module1.js');
var module1 = require('module1');
package.json : app.js
{
"name": "nano-server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"express": "^4.14.0",
"mysql": "^2.11.1",
"socket.io": "^1.4.8",
"module1": "0.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC"
}
package.json : module1
{
"name": "module1",
"version": "0.0.0",
"description": "get something",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": {
"name": "sergey"
},
"license": "BSD-2-Clause",
"readme": "ERROR: No README data found!",
"_id": "module1#0.0.0",
"dist": {
"shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
"tarball": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
},
"_from": "module1#latest",
"_npmVersion": "1.3.11",
"_npmUser": {
"name": "sergey-user",
"email": "aaa#mail.ru"
},
"maintainers": [
{
"name": "sergey-user",
"email": "aaa#mail.ru"
}
],
"directories": {},
"_shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
"_resolved": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
}
directory
_server
.git
node_modules
.bin
express
module1
index.js
package.json
mysql
node-mysql
node-uuid
socket.io
package.json
server.js
Try var module1 = require('./module1');
Adding your module as a dependency to your application would resolve this issue. To achieve that try the below command.
npm install module1 --save
Hope this helps!
install npm -g and try again afterwords.
In my case, after trying everything without any success, updating node helped (v10.3.1 -> v12.13.1).

Categories

Resources