Node modules are not exporting - node.js

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.

Related

Trying to upgrade asp.net MVC project to React but faced this Error TS6200

I Have Integrated React with Node-js running environment inside my existing asp.net MVC project I am trying to convert the existing Razor pages from the View folder into React base,
Now everything went smooth until I faced this error when I tried to build the app it seemed that It came from the node_modules file:
Severity Code Description Project File Line Suppression State
Error TS6200 (TS) Definitions of the following identifiers conflict with those in another file: ImportExportKind, TableKind, ValueType, ExportValue, Exports, ImportValue, Imports, ModuleImports, name, AlgorithmIdentifier, BigInteger, BlobPart, BodyInit, BufferSource, CanvasImageSource, DOMHighResTimeStamp, EventListenerOrEventListenerObject, Float32List, FormDataEntryValue, GLbitfield, GLboolean, GLclampf, GLenum, GLfloat, GLint, GLint64, GLintptr, GLsizei, GLsizeiptr, GLuint, GLuint64, HashAlgorithmIdentifier, HeadersInit, IDBValidKey, ImageBitmapSource, Int32List, MessageEventSource, NamedCurve, OnErrorEventHandler, PerformanceEntryList, ReadableStreamController, ReadableStreamDefaultReadResult, ReadableStreamReader, RequestInfo, TexImageSource, TimerHandler, Transferable, Uint32List, VibratePattern, BinaryType, ClientTypes, ColorSpaceConversion, EndingType, IDBCursorDirection, IDBRequestReadyState, IDBTransactionMode, ImageOrientation, KeyFormat, KeyType, KeyUsage, NotificationDirection, NotificationPermission, PermissionName, PermissionState, PremultiplyAlpha, PushEncryptionKeyName, ReferrerPolicy, RequestCache, RequestCredentials, RequestDestination, RequestMode, RequestRedirect, ResizeQuality, ResponseType, ServiceWorkerState, ServiceWorkerUpdateViaCache, WebGLPowerPreference, WorkerType, XMLHttpRequestResponseType GoTo.Tickets.UI ....nuget\packages\microsoft.typescript.msbuild\4.2.4\tools\tsc\lib.dom.d.ts 25 Active
now I have another many errors but they all belongs to the same concept
I have installed with it also Webpack and babel
this is my package.json file:
{
"name": "goto.tickets.ui",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.18.9",
"#babel/core": "^7.18.9",
"#babel/plugin-proposal-class-properties": "^7.18.6",
"#babel/preset-env": "^7.18.9",
"#babel/preset-react": "^7.18.6",
"babel-loader": "^8.2.5",
"babel-polyfill": "^6.26.0",
"browser-sync-webpack-plugin": "^2.3.0",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-notifier": "^1.15.0"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
this is the guides I used to do this:
https://paddyguest.medium.com/adding-react-to-an-existing-asp-net-mvc-project-part-1-setting-up-the-project-da688212da80#ab5f
https://paddyguest.medium.com/adding-react-to-an-existing-asp-net-mvc-project-part-2-integration-c58428094ca0
And I'm currently at part two 3.
Thanks for everything!!

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'

When trying to create a release pipeline in Azure DevOps (I have used a Nodejs application) it exits with an error. ##[error]Bash exited with code '1'

NodeJs application that I have been trying to deploy, always shows an error:
[error]Bash exited with code '1'.
{
"name": "test1",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js",
"build": " "
},
"keywords": ["app.js"],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"connect-flash": "^0.1.1",
"ejs": "^2.6.2",
"express": "^4.17.1",
"express-ejs-layouts": "^2.5.0",
"express-session": "^1.16.2",
"i": "^0.3.6",
"mongoose": "^5.6.5",
"passport": "^0.4.0",
"passport-local": "^1.0.0"
},
"devDependencies": {
"nodemon": "^1.19.1"
},
"description": ""
}
First, Please check the path in the artifacts weather the files that are required exists in the artifacts or not. Download the artifact that you are trying to deploy and make sure the package.json and app.js is in the root directory (or in the deirectory that you are trying to deploy).
For further diagnoisis i think you need to provide your question with more detail descriptions like
What build script was used to make the artifact.
What environment was used for app deployment.

npm run scripts does not working

I have just initialized a new project with Node.js and trying making the scripts in package.json file to be working.
For example I have the next package.json file:
{
"name": "my-app-name",
"version": "1.0.0",
"description": "Description server",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Something LTD",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"cron": "^1.3.0",
"crypto": "^1.0.1",
"docusaurus-init": "^1.0.2",
"exceljs": "^1.5.0",
"express": "^4.16.3",
"express-limiter": "^1.6.1",
"jsonwebtoken": "^8.3.0",
"mongojs": "^2.6.0",
"npm": "^6.1.0",
"point-in-polygon": "^1.0.1",
"request": "^2.87.0",
"socket.io": "^2.1.1",
"socket.io-redis": "^5.2.0",
"xmldom": "^0.1.27"
},
"devDependencies": {
"t4u": "^1.0.0"
}
}
Then I either trying run npm test or npm start or npm run start
but all of them just doing nothing and returns nothing in console. Even the test script just not printing anything.
I have tried to do:
npm config set --ignore-scripts false
However that did not work.
npm config set ignore-scripts false
Was solved the issue.
npm run-script start worked for me (npm run is an alias to npm run-script as stated in doc but not sure why alias didnt work)
hope this helps people who are still facing the issue after setting ignore-script as false
On Windows you can also edit directly a file on the following location
C:\Users\[Your username]\.npmrc
and set ignore-scripts=false

Why does NodeJS require me to use the full directory for downloaded modules?

For something like Express for example, which does not come with Node by default. I have to use var express = require('C:/Users/User/node_modules/express'); instead of just var express = require('express');. I notice the modules which come by default such as http aren't in the same location as the ones I install. So what do I need to do in order to not have to write the whole directory. If it makes any difference I keep all my Node projects in C:/Node/, not the default one.
This is happening because you probably don't have node modules installed locally. For that you need a package.json file which you can get by running
npm init
This will ask you some questions about your project and will set up node locally. A package.json file will be created which should look something like this (without dependencies).
{
"name": "express-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "Link to your repository"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^1.0.2",
"body-parser": "^1.17.2",
"chalk": "^2.0.1",
"compression": "^1.7.0",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"express": "^4.15.3",
"glob": "^7.1.2",
"moment": "^2.18.1",
"mongoose": "^4.11.3",
"morgan": "^1.8.2",
"passport": "^0.3.2",
"path": "^0.12.7",
"yargs": "^8.0.2"
}
}
You can then add the node modules you want by putting them in dependencies and running
npm install
If you want to add node modules from commond line you can use
npm install package-name --save

Resources