internalBinding('errors').triggerUncaughtException( - javascript

I am facing the issue during installation of chalk module with node version 14 using command npm install chalk and facing this issue could not find any solution.
package.json file
"name": "notes-app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jayant",
"license": "ISC",
"dependencies": {
"chalk": "^5.0.0"
},
"type": "module"
}
app.js file
import chalk from 'chalk';
console.log(chalk.blue('Hello world!'));
Got this error while running app.js with node version 14
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'C:\previous data\Jayant\Programs\node-tutorials\notes-app\node_modules\chalk\source\node_modules\' imported from C:\previous data\Jayant\Programs\node-tutorials\notes-app\node_modules\chalk\source\index.js
at packageMainResolve (internal/modules/esm/resolve.js:458:9)
at packageResolve (internal/modules/esm/resolve.js:601:14)
at moduleResolve (internal/modules/esm/resolve.js:646:14)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:692:13)
at Loader.resolve (internal/modules/esm/loader.js:97:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)
at link (internal/modules/esm/module_job.js:41:36) {
code: 'ERR_MODULE_NOT_FOUND'
}

Related

Failed launching test session: Error: Couldn't initialise "#wdio/cucumber-framework"

I am setting up the wdio using command "npm init wdio" and try to run the test files. it is giving below error
Failed launching test session: Error: Couldn't initialise "#wdio/cucumber-framework". [0-0] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/formatter/helpers/event_data_collector' is not defined by
Below is my package.json file
"name": "wdio-new",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wdio": "wdio run wdio.conf.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#wdio/cli": "^7.16.12",
"#wdio/cucumber-framework": "^7.16.12",
"#wdio/local-runner": "^7.16.12",
"#wdio/spec-reporter": "^7.16.11",
"chromedriver": "^96.0.0",
"wdio-chromedriver-service": "^7.2.2"
}
}
I managed to fix this issue by reinstalling node and checking the option to "Automatically install the necessary tools" during setup

rollup.js_Bundle automatic update

I'm trying to biuld bundling through rollup.js in VSCode.
My directory:
----MyProject
--------\node_modules
-----------\.bin
-----------\rollup
--------index.js
--------index.html
--------bundle.js
--------package-lock.json
--------package.json
In my .html file I have connection with bundle.js, all changes which I'm doing in index.js must automatically be updated in bundle.js. But it's only working when I run in terminal this command: rollup index.js --file bundle.js
My package.json:
{
"name": "npm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"rollup": "^2.34.2"
}
}
What do I need to do to make this system works automatically?
Firstly, I didn't have config file, so I've created rollup.config.js:
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
const watch = process.env.ROLLUP_WATCH
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
watch && serve('dist'),
watch && livereload()
]
}
Then I added these 2 scripts into package.json:
"build": "rollup -c",
"dev": "rollup -c -w"
And run in terminal: npm run dev
My credits to vladshcherbin for help!

Babel is outputting a file which node failes to run citing "require is not defined"

I am encountering an error as displayed below. The error arrises when I run the following command in an attempt to build and run a node project with babel. The issue arose on a larger project, I recreated the basic components in order to better diagnose the issue, but I am stumped now.
When running
babel --extensions ".ts" index.ts -o dist/index.js;node dist/index.js
node returns
file:///Users/sadeksyed/Documents/Programming%20Projects/HC/test-babel-proj/dist/server.js:3
var _path = _interopRequireDefault(require("path"));
^
ReferenceError: require is not defined
at file:///Users/sadeksyed/Documents/test-babel-proj/dist/server.js:3:13
at ModuleJob.run (internal/modules/esm/module_job.js:110:37)
at async Loader.import (internal/modules/esm/loader.js:179:24)
This file index.ts looks like:
import path from "path";
var __dirname = path.resolve();
import http from "http";
import dotenv from "dotenv";
dotenv.config({ path: __dirname + "/test/.env" });
console.log(process.env.PORT);
.babelrc
{
"presets": [
[
"#babel/preset-env",
{
"targets": {
"esmodules": true
}
}
],
"#babel/preset-typescript"
],
"plugins": ["#babel/plugin-transform-runtime"]
}
package.json
{
"name": "test-babel-proj",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.10.2",
"#babel/plugin-transform-runtime": "^7.10.1",
"#babel/plugin-transform-typescript": "^7.10.1",
"#babel/preset-env": "^7.10.2",
"#babel/preset-typescript": "^7.10.1",
"#types/node": "^14.0.13"
},
"dependencies": {
"dotenv": "^8.2.0"
}
}
I've been attempting to resolve this problem all day yesterday and today. Any help would be appreciated!

node.js local modules :cannot find module error

I am trying to implement local modules in my application
1.Project root folder i have created folder named test with a file named index.js
module.exports = {
myFunction:function(){
console.log('ok');
}
}
2.Added the following in package.json in the root folder
"dependencies": {
"test-module": "file:test"
}
3.When i try to import var module = require('test-module'); in app.js i got this error
Cannot find module 'test-module'
you can provide a path to a local directory that contains a package
{
"name": "baz",
"dependencies": {
"bar": "file:../foo/bar"
}
}
and perform npm install -s or npm install --save reference
To add on #Blaze answer, if you follow the steps (Local Paths) to install a local module, it will sort out for you the local dependency in your package.json:
npm i ./test --save
That will produce the correct local dependency entry in your dependencies in the root package.json:
"test-module": "file:test"
assuming test-module is the name in the local dep package.json.
This is how it should look like:
Make sure your test folder has a package.json.
test/package.json should have a "name" field with the value "test-module" (ie, same name as the dependency in your root package.json.
My files:
test/package.json
{
"name": "test-module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
test/index.js
module.exports = {
t:() => console.log('t')
};
package.json
{
"name": "t",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"test-module": "file:test"
}
}
app.js
t = require('test-module');
t.t();
This is working for me.

loading "gruntfile.js" tasks...ERROR

Ive searched this for over an hour now and no ones post helped me with my problem so i need to post i guess lol
I have some pretty simple code for a grunt task im trying to run but im getting an error.
module.exports = function(grunt){
grunt.initconfig({
pkg: grunt.file.readJSON ('package.json'),
uncss: {
dist: {
files: {
'css/style.css' : ['index.html']
}
}
}
});
grunt.loadNpmTasks('grunt-uncss');
grunt.registerTask('default',['uncss']);
};
my package file is as follows:
{
"name": "Grunt",
"version": "1.0.0",
"description": "grunt",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"tt"
],
"author": "troy",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-uncss": "^0.4.3"
}
}
The Error im getting is:
Loading "gruntfile.js" tasks...ERROR
TypeError: undefined is not a function
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
Any assistance is greatly appreciated

Categories