Duplicate lexical declaration; cannot redefine let or const variables - javascript

I am using VS 2015 Community for a Node application using nodejstools tool.
Using the following code I get an error in "Error List" palette. Despite this, the application runs fine.
I am wondering why this error happens in my code or it is a bug related to VS IDE.
'use strict';
const Q = require('q')
const spawn = require('child_process').spawn;
const exec = require('child_process').exec;
const fs = require('fs');
const del = require('del');
const removeDirectories = require('remove-empty-directories');
Edit:
Source code for this exception.
Bug report

Related

buildkite error : The plugins file is missing or invalid. Cannot find module 'xlsx' when running cypress test . Runs fine on local

I am getting error when running the cypress test on buildkite as below:
Status: Downloaded newer image for cypress/included:6.1.0
[2022-01-31T10:32:13Z] Your pluginsFile is set to /e2e/cypress/plugins/index.js, but either the file is missing, it contains a syntax error, or threw an error when required. The pluginsFile must be a .js, .ts, or .coffee file.
Or you might have renamed the extension of your pluginsFile. If that's the case, restart the test runner.
Please fix this, or set pluginsFile to false if a plugins file is not necessary for your project.
Error: Cannot find module 'xlsx'
Require stack:
/e2e/cypress/plugins/read-xlsx.js
/e2e/cypress/plugins/index.js
the same test runs fine on local on both browser and headless
"xlsx" is present in the package.json as both dependencies and dev dependencies.
code inside read-xlsx
const XLSX = require("xlsx");
const fs = require("fs");
const read = ({file, sheet}) => {
const buf = fs.readFileSync(file);
const workbook = XLSX.read(buf, { type: 'buffer' });
const rows = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
return rows
}
module.exports = {
read
}
Someone please help
I had the same problem.
But in my case, was an issue with case sensitive.
I put 'XLSX' inside the require in the read-xlsx.js file.
My read-xlsx.js file became like this and worked:
const fs = require('fs')
const XLSX = require('xlsx')

PubNub Node util.inherit is not a function

After adding the pubnub node sdk to my nativescript Project
npm install pubnub
I get following error message:
> System.err: Error: Parsing XML at 58:9 System.err: > util.inherits is
> not a function
I simply require it like this:
const PubNub = require("pubnub");
Any idea how that could happen?
Currently, PubNub Node SDK is not compatible with NativeScript v5. It is compatible with NativeScript v3. PubNub is investigating changes that can be made to be compatible with NativeScript v5.
Workaround by #Jon_not_doe_xx:
In the webpack.config.js file, add this in the head:
const shims = require('nativescript-nodeify/shims.json');
const aliases = {};
for (const key of Object.keys(shims)) {
const value = shims[key];
aliases[key + '$'] = value;
}
aliases['inherits$'] = 'inherits/inherits_browser';
// Remove hook, as this will only cause problems at this point.
// Checking and deleting within webpack ensures
// that it will be deleted during a cloud build.
let fs = require("fs");
let process = require("process");
if (fs.existsSync(__dirname + "/hooks/after-prepare/nativescript-nodeify.js")) {
process.stdout.write("Found evil hook, deleting...\n");
fs.unlinkSync(__dirname + "/hooks/after-prepare/nativescript-nodeify.js");
process.stdout.write("Should be fixed now.\n");
}
else process.stdout.write("Hooks seem clean, moving on.\n");
Also, modify the alias object inside the resolve object in the webpack.config.js file:
alias: {
'~': appFullPath,
'#': appFullPath,
...aliases
},

How to add git hash to my project on build - Webpack

I would like to access some information about my project for testing purposes. For example, I'd like to append the git hash or and installed module version as a param on one of my requests. What I came up with (which works) is to include a prebuild script in my package.json
"prebuild": "node scripts/prebuild.js"
and in that script
var fs = require('fs');
var child_process = require('child_process');
const revision = child_process
.execSync('git rev-parse HEAD')
.toString().trim()
const module_version = child_process
.execSync('npm view module version')
.toString().trim()
const params = `module.exports = {
git_hash: '${revision}',
module_version: '${module_version}'
};`
fs.writeFileSync(__dirname + '/../src/helpers/params.js', params, () => {
console.log('Prebuild finished');
});
and then import that file where needed
import params from './src/helpers/params';
However this seems kinda hacky to me and I wonder if there's a way to utilize webpack to help me achieve this in a better/safer way.

TypeError: require(...) is not a function Express.js

I need help. I have this error when I run npm start:
/Users/telecreative/Documents/cafemates micro-services/cafemates-users-services/database/index.js:8
const pgp = require("pg-promise")(options) ^
On another computer, script running, with node version and npm version was same:
TypeError: require(...) is not a function
const express = require("express")
const app = express()
require('dotenv').config({path:__dirname+'/./../../.env'})
const promise = require("bluebird")
const options = {
promiseLib: promise
}
const pgp = require("pg-promise")(options)
const config = {
user: process.env.DATABASE_USER,
host: process.env.DATABASE_HOST,
database: process.env.DATABASE,
password: process.env.DATABASE_PASSWORD,
port: process.env.DATABASE_PORT
}
const db = pgp(config);
module.exports = db
Try running npm install --save pg-promise bluebird from the project root and then reload the app.
This: require("pg-promise") simple does not return function.
Therefore when you use require("pg-promise")(...) it tries to use it as function and then fails, because it is not a function.
You can try console.log(require("pg-promise"))) to see whats inside.
Solved
wrong me, I copy the json package., from the existing one, the best way should be to install one by one.

MongoClient TypeError

I am a NodeJS newbie and JS can-kicker trying out DI for the first time. Here are the questions I looked at before deciding to ask mine, since they show the same error: [1][2]
Running my entry point yields:
this.client = new MongoClient(server);
^
TypeError: undefined is not a function
Entry point
var config = require('./config.json');
var Providers = require('./providers');
var providers = new Providers(config.db);
console.log(providers);
./providers/index.js
Both AssetProvider and UserProvider suffer the same error. I think I only need to show one.
module.exports = function Provider(dbConfig)
{
var UserProvider = require('./userProvider');
var AssetProvider = require('./assetProvider');
this.users = new UserProvider (dbConfig.name, dbConfig.host, dbConfig.port);
this.assets = new AssetProvider(dbConfig.name, dbConfig.host, dbConfig.port);
}
./providers/userProvider.js
Problem line marked
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var Server = mongodb.Server;
var ObjectID = mongodb.ObjectID;
var UserProvider = function (database, host, port) {
var server = new Server(host, port, { auto_reconnect: true });
// Error is here
this.client = new MongoClient(server);
this.client.open(function (error, client) {
this.db = client.db(database);
});
};
// ...a bunch of prototype stuff...
// ...
module.exports = UserProvider;
From what I have read in other locations online, I don't see anything wrong with my syntax. I have tried the following declaration...
function UserProvider(database, host, port)
as opposed to
var UserProvider = function(database, host, port)
Everything else I did was comparable to slapping a car engine with a wrench. The truth is, I simply do not understand what is so wrong here, but I do know that I just want to make a composition of objects across files so that my entry point can readily use all providers through a single object.
JohnnyHK turned out to be correct about it being a version issue.
Oddly enough, the error did not go away when running npm update mongodb
However, it did go away when I ran npm install mongodb a second time.
No changes were made in the code, and mongodb was already inside the local
node_modules folder. Even so, I suspect this had to do with a discrepancy between an instance in node_modules and an instance in NODE_PATH.
I'm only speculating as to why exactly npm install solved the problem considering the latest version should have been installed. All I know is that the error is gone and the code is working.
Thank you for the comments!
I got exactly the same issue. After a quick research I realised that I have an old mongodb module version (0.9.x). After installing the latest (1.13.19) - the issue has been fixed.
npm install mongodb#1.3.13

Categories

Resources