error TS2305: Module '"tls"' has no exported member 'TLSSocketOptions' - node.js

I'm trying to connect to MongoDB using the MongoDB drivers in a Node.js project but am having issues compiling, and receive the titular error "node_modules/mongodb/mongodb.ts34.d.ts:31:10 - error TS2305: Module '"tls"' has no exported member 'TLSSocketOptions'." Any help for how to resolve this apparent node package issue would be very helpful!
When I inspect, the tls package it has TLSSocketOptions and appears to have it exported through the following at the end of the file
declare module 'node:tls' {
export * from 'tls';
}
My package.json
{
"main": "wwwroot/index.js",
"bin": "wwwroot/index.js",
"scripts": {
"start": "node ./wwwroot/index.js",
"dev": "ts-node src/",
"compile": "npx tsc",
"postinstall": "npx tsc"
},
"engines": {
"node": "14.18.1"
},
"dependencies": {
"#discordjs/uws": "^10.149.0",
"discord.js": "^11.4.2",
"mongodb": "^4.1.4",
"snoowrap": "^1.23.0"
},
"devDependencies": {
"#types/node": "^11.15.54",
"pkg": "^4.5.1",
"ts-node": "^10.4.0",
"tslint": "^5.16.0",
"typescript": "^3.9.10"
}
}

Your version of #types/node seems to be ancient and I guess the export in question was added since then

Related

I'm getting this error while running the code in React Native error : node_modules\expo\AppEntry.js: [BABEL]: Cannot find module 'node:path'

I am getting this error while running the code in React Native expo with Tailwind
Android Bundling failed 25ms
error: node_modules\expo\AppEntry.js: [BABEL]: Cannot find module 'node:path'
Require stack:
C:\Users\HPX\ipx\node_modules\nativewind\dist\babel\index.js
C:\Users\HPX\ipx\node_modules\nativewind\babel.js
C:\Users\HPX\ipx\node_modules#babel\core\lib\config\files\module-types.js
C:\Users\HPX\ipx\node_modules#babel\core\lib\config\files\configuration.js
C:\Users\HPX\ipx\node_modules#babel\core\lib\config\files\index.js
C:\Users\HPX\ipx\node_modules#babel\core\lib\index.js
C:\Users\HPX\ipx\node_modules\metro-transform-worker\src\index.js
C:\Users\HPX\ipx\node_modules\metro\src\DeltaBundler\Worker.flow.js
C:\Users\HPX\ipx\node_modules\metro\src\DeltaBundler\Worker.js
C:\Users\HPX\ipx\node_modules\jest-worker\build\workers\processChild.js (While processing: C:\Users\HPX\ipx\node_modules\nativewind\babel.js)
This is my AppEntry.js file :
import registerRootComponent from 'expo/build/launch/registerRootComponent';
import App from '../../App';
registerRootComponent(App);
This is my package.json file :
{
"name": "ipx",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"expo": "~47.0.3",
"expo-status-bar": "~1.4.2",
"nativewind": "^2.0.11",
"react": "18.1.0",
"react-native": "0.70.5",
"tailwindcss": "^3.2.3"
},
"devDependencies": {
"#babel/core": "^7.12.9"
},
"private": true
}
Please replay if you have a solution for this
You cannot use TailWind CSS with react native directly, as styling for HTML and ReactNative is different, instead you can use some library like twrnc
When you installed NativeWind there was an error in your console that your version of Node does not match the minimal requirements. You need to update to >=14.18
// from the NativeWind package.json
"engines": {
"node": ">=14.18"
},

Cannot find name 'CanvasRenderingContext2D' [duplicate]

I am setting a web app up in TypeScript and I seem to be missing some basic types I need.
When I compile (npm run build), I get the following errors,
error TS2304: Cannot find name 'HTMLElement'.
error TS2304: Cannot find name 'SVGElement'.
error TS2304: Cannot find name 'EventTarget'.
error TS2304: Cannot find name 'TouchEvent'.
error TS2304: Cannot find name 'MouseEvent'.
error TS2304: Cannot find name 'PointerEvent'.
Based on my Googling I assuming I am missing something basic in my project setup. It seems like these types are just assumed to be there with Typescript.
EDIT: Specially it should be part of the ES6 types, https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts.
Here is my package.json file:
{
"name": "wip",
"version": "1.0.0",
"description": "",
"main": "index.html",
"dependencies": {
"hammerjs": "2.0.8"
},
"devDependencies": {
"#types/chai": "3.4.35",
"#types/mocha": "2.2.39",
"#types/node": "7.0.5",
"#types/hammerjs": "2.0.34",
"chai": "3.5.0",
"mocha": "3.2.0",
"safe-mock": "0.2.0",
"ts-node": "2.1.0",
"tslint": "4.5.1",
"typescript": "2.2.1",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.1"
},
"scripts": {
"test": "mocha test --require ts-node/register test/**/*.ts && npm run build",
"dev": "webpack-dev-server --watch --content-base . -d --progress",
"build": "tsc"
},
"author": "",
"license": "ISC"
}
Any suggestions?
Try adding the following lib section to your tsconfig.json file.
{
"compilerOptions": {
"lib": [
"es2016",
"dom"
]
}
}
Additional answer for testing.
If using mocha, you also need to tell mocha about the DOM environment using jsdom.
https://journal.artfuldev.com/unit-testing-node-applications-with-typescript-using-mocha-and-chai-384ef05f32b2
$ npm install jsdom jsdom-global --save-dev
So your "test" script would add -r jsdom-global/register:
{
"scripts": {
"test": "mocha test -r ts-node/register -r jsdom-global/register test/**/*.ts && npm run build"
}
}

Node modules are not exporting

my node modules are not importing. I tried in export default and export const and each and every way. every each times I get either reference error or a syntax error.
I get reference error when i update my code like below.(ReferenceError: require is not defined)
const viewEngine = require( './config/viewEngine');
I get syntax error when i update my code like below.(SyntaxError: The requested module './config/viewEngine' does not provide an export named 'default')
import viewEngine from './config/viewEngine';
I get syntax error when i update my code like below.(SyntaxError: The requested module './config/viewEngine' does not provide an export named 'viewEngine')
import {viewEngine} from './config/viewEngine';
and the ways i tried to export:
module.exports = configViewEngine;
module.exports = {configViewEngine};
and my dotenv is not getting defined. I tried every each ways to import dotenv too.
here is my package.json.
{
"name": "chatbot",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon --experimental-modules --es-module-specifier-resolution=node src/server.js"
},
"type": "module",
"author": "",
"license": "ISC",
"dependencies": {
"#babel/core": "^7.14.3",
"#babel/node": "^7.14.2",
"#babel/preset-env": "^7.14.2",
"body-parser": "^1.19.0",
"browserify": "^17.0.0",
"dotenv": "^10.0.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"localtunnel": "^2.0.1",
"nodemon": "^2.0.7",
"npm-upgrade": "^3.0.0"
}
}
I use windows 10.
please help thanks!
After upgrading npm version it worked.

Cannot download GraphQL schema from endpoint

I'm currently using graphql-cli from Prisma to download the schema from endpoint. But, even after I deploy the changes I made to my schema, which gets deployed successfully, whenever I try to download the schema, I get project prisma - No changes. And the generated prisma.graphql is left unchanged.
I use the following command to download the schema:
graphql get-schema -p prisma --dotenv config/dev.env
dev.env is simply to get PRISMA_ENDPOINT=http://localhost:4466/ environment variable.
I tried to generate prisma.graphql in a different way by having the following in prisma.yml:
endpoint: ${env:PRISMA_ENDPOINT}
datamodel: datamodel.prisma
generate:
- generator: graphql-schema
output: ./generated/
And executed prisma generate, but I get the error:
▸ [WARNING] in
/Users/F/Documents/d/server/prisma/prisma.yml: A valid
environment ▸ variable to satisfy the declaration
'env:PRISMA_ENDPOINT' could not be found.
Tried stopping and recreating Docker as well as deleting the node_module and re-installing, but to no avail.
My package.json:
{
"name": "graphql-basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node dist/index.js",
"heroku-postbuild": "babel src --out-dir dist --copy-files",
"dev": "env-cmd ./config/dev.env nodemon src/index.js --ext js,graphql --exec babel-node",
"test": "env-cmd ./config/test.env jest --watch --runInBand",
"get-schema": "graphql get-schema -p prisma --dotenv config/dev.env"
},
"jest": {
"globalSetup": "./tests/jest/globalSetup.js",
"globalTeardown": "./tests/jest/globalTeardown.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"#babel/polyfill": "^7.0.0",
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"bcryptjs": "^2.4.3",
"cross-fetch": "^2.2.2",
"env-cmd": "^8.0.2",
"google-auth-library": "^4.2.3",
"graphql-cli": "^3.0.14",
"graphql-yoga": "^1.14.10",
"jsonwebtoken": "^8.3.0",
"prisma-binding": "^2.1.1"
},
"devDependencies": {
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"jest": "^23.5.0",
"nodemon": "^1.17.5"
},
"resolutions": {
"graphql": "^14.5.8"
}
}
To fix the error "variable to satisfy the declaration 'env:PRISMA_ENDPOINT' could not be found." when calling prisma generate you should either set the PRISMA_ENDPOINT variable manually or load it via dotenv. For example you could run npx dotenv -- prisma generate to load the env vars from your .env file.
To download the schema from the endpoint via graphql get-schema make sure to provide a properly configured .graphqlconfig.yml and provide the correct project.
A sample configuration for a prisma project could look like this:
projects:
prisma:
schemaPath: 'src/schema.graphql'
extensions:
endpoints:
default: 'http://localhost:4000/graphql'
database:
schemaPath: 'src/generated/prisma.graphql'
extensions:
prisma: 'database/prisma.yml'
endpoints:
default: 'http://localhost:4466'

Javascript Trying to run AMIjs examples in local it does not work

Hello and thank you for reading this.
I would like to load the examples in local WebStorm IDE. In particular I am trying to load the loaders example:
https://github.com/FNNDSC/ami/tree/dev/examples/viewers_upload
The problem I get is the default imports look like thay are not properly set:
So if I try to run npm install
I get this error:
Can not install Node.js module: "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" install base/core/core.utils
Standard error:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "base\core\core.utils" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\YonePC\AppData\Roaming\npm-cache\_logs\2018-01-16T18_50_29_864Z-debug.log
I thought it was related to my package.json but it looks like it has all the dependencies set up:
{
"name": "ami.js",
"version": "0.0.23-dev",
"main": "build/ami.js",
"keywords": [
"ami",
"ami.js",
"three.js",
"webgl",
"dicom",
"nifti",
"awesome",
"medical",
"imaging",
"xtk",
"nrrd",
"vtk",
"stl",
"trk"
],
"author": {
"name": "Nicolas Rannou",
"email": "nicolas#eunate.ch",
"url": "https://eunate.ch"
},
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://fnndsc.github.io/ami"
},
"config": {
"threeVersion": "87",
"amiCDN": "https://cdnjs.cloudflare.com/ajax/libs/ami.js",
"gaKey": "UA-39303022-3",
"babel": "--module-bind js=babel-loader --colors --display-error-details"
},
"dependencies": {
"dicom-parser": "1.7.3",
"image-JPEG2000": "OHIF/image-JPEG2000#master",
"jpeg-lossless-decoder-js": "1.2.3",
"math-float32-to-binary-string": "^1.0.0",
"nifti-reader-js": "v0.5.3",
"nrrd-js": "^0.2.1",
"pako": "1.0.1",
"three": "0.87.0"
},
"scripts": {
"build:ami": "webpack --config webpack.config.build.js",
"build:ami:prod": "cross-env NODE_ENV=production yarn build:ami",
"build:clean": "rimraf -rf build/*",
"build:clean:hot": "rimraf -rf build/*.hot-update.*",
"dev:ami": "webpack --config webpack.config.build.js --hot --watch --colors",
"dist:ami": "yarn build:clean && yarn build:ami && yarn build:ami:prod && yarn doc",
"dist:examples": "node ./scripts/buildDist.js && node ./scripts/router.js examples deploy",
"dist:clean": "rimraf -rf dist/*",
"analyze:ami": "cross-env NODE_WEBPACK_ANALYZE=true yarn build:ami",
"analyze:ami:prod": "cross-env NODE_WEBPACK_ANALYZE=true yarn build:ami:prod",
"clean": "yarn build:clean && yarn dist:clean",
"example": "node ./scripts/router.js examples",
"lesson": "node ./scripts/router.js lessons",
"gen:index:examples": "node ./scripts/genIndexFiles.js examples",
"gen:index:examples:ga": "cross-env NODE_GA=true node ./scripts/genIndexFiles.js examples",
"gen:index:lessons": "node ./scripts/genIndexFiles.js lessons",
"gen:index:lessons:cdn": "node ./scripts/genIndexFiles.js lessons cdn",
"test": "karma start",
"lint": "eslint src/**/*.js",
"doc": "jsdoc -p -r -R README.md -c jsdoc.json -d dist/doc src",
"ami": "yarn lint && yarn dist:ami && yarn test",
"deploy": "yarn dist:clean && yarn build:clean && yarn dist:ami && yarn dist:examples && gh-pages -d dist"
},
"devDependencies": {
"babel-cli": "latest",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-runtime": "^6.26.0",
"compression-webpack-plugin": "^1.0.1",
"cross-env": "^3.2.3",
"eslint": "latest",
"eslint-config-google": "latest",
"gh-pages": "latest",
"glslify": "5.1.0",
"jasmine-core": "latest",
"jsdoc": "jsdoc3/jsdoc#master",
"karma": "latest",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "latest",
"karma-sinon": "^1.0.5",
"karma-spec-reporter": "latest",
"karma-webpack": "^2.0.4",
"live-server": "^1.1.0",
"puppeteer": "^0.13.0",
"rimraf": "^2.6.1",
"rollup-plugin-node-builtins": "^2.1.2",
"shelljs": "latest",
"sinon": "^2.0.0",
"uglifyjs-webpack-plugin": "^1.0.0-beta.3",
"webpack": "^3.7.1",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-watch-livereload-plugin": "^0.0.1"
},
"engines": {
"node": ">=6.9.0"
}
}
In addition I looked and tried to find if I would have Node modules isntalled, but as it does not appear in the package.json they are not installed by default:
However I do have node installed:
Microsoft Windows [Versión 6.3.9600]
(c) 2013 Microsoft Corporation. Todos los derechos reservados.
C:\Users\YonePC\WebstormProjects\ATLAS>node -v
v8.9.0
If I execute index.html it says on the developer console:
'Uncaught SyntaxError: Unexpected identifier'
And the line being said is:
import CoreUtils from 'base/core/core.utils';
If I try to redo the imports with IDE's help, this is the result:
After executing the updated index.html:
viewers_upload.js:5 Uncaught SyntaxError: Unexpected identifier
And the line referenced is:
import HelpersLut from "../../src/helpers/helpers.lut";
If I try to use the web CDN library version with:
I need to delete all imports and use the web library version's classes as follows:
I can execute the index.html and trigger the loader:
However I can not do it infinitely because of the class to parseUrl is being on the disk library and not in the web library:
The console says:
'Uncaught ReferenceError: CoreUtils is not defined
at HTMLInputElement.readMultipleFiles (viewers_upload.js:429)
readMultipleFiles # viewers_upload.js:429'
Could you help me please?
Thank you for your time reading this.
EDIT: I am still trying to get that example working on local. So far I have been able to include AMI library's files linking for example:
viewers_upload.js
let dataUrl = CoreUtils.parseUrl(evt.target.files[i].name);
Instead of the normal import generated by the IDE:
import CoreUtils from "../../src/core/core.utils";
Using a direct load:
index.html
<script src="../../src/core/core.utils.js"></script>
However I can not keep doing this infinitely because of the core.utils.js uses import so then the browser reports an error:
Uncaught SyntaxError: Unexpected identifier
In line:
import Validators from './core.validators';
Could you help me please???
To run an example you should:
start dev server: yarn example <example name> (in your case yarn example viewers_upload)
go to localhost:8081 in your web browser

Resources