I'm trying to use the bcrypt-package inside a vue-electron project, but there is an N-api version issue when I try to run it:
Uncaught Error: The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module.
I'm running node 12.16.1.
I read up on the documentation about N-API, and according to that version matrix, it is not possible I have version 1 installed. But I can't find any further documentation on how to install/configure/manage these N-API versions.
My package.json:
{
"version": "0.0.1",
"license": null,
"engines": {
"node": "12.16.x"
},
"main": "./dist/electron/main.js",
"scripts": {
"build": "node .electron-vue/build.js && electron-builder",
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "node .electron-vue/dev-runner.js",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": ""
},
"build": {
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/icon.icns"
},
"win": {
"icon": "build/icons/icon.ico"
},
"linux": {
"icon": "build/icons"
}
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.27",
"#fortawesome/free-solid-svg-icons": "^5.12.1",
"#fortawesome/vue-fontawesome": "^0.1.9",
"axios": "^0.18.0",
"bcrypt": "^4.0.1",
"bootstrap": "^4.4.1",
"bootstrap-vue": "^2.7.0",
"dotenv": "^8.2.0",
"dotenv-webpack": "^1.7.0",
"mongoose": "^5.9.4",
"mongoose-uuid2": "^2.3.0",
"portal-vue": "^2.1.7",
"uuid": "^7.0.2",
"vue": "^2.5.16",
"vue-electron": "^1.0.6",
"vue-i18n": "^8.15.5",
"vue-router": "^3.0.1",
"vuex": "^3.0.1",
"vuex-electron": "^1.0.0"
},
"devDependencies": {
"ajv": "^6.5.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"cfonts": "^2.1.2",
"chalk": "^2.4.1",
"copy-webpack-plugin": "^4.5.1",
"cross-env": "^5.1.6",
"css-loader": "^0.28.11",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^2.0.4",
"electron-builder": "^20.19.2",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "0.4.0",
"multispinner": "^0.2.1",
"node-loader": "^0.6.0",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1",
"vue-html-loader": "^1.2.4",
"vue-loader": "^15.2.4",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.16",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4",
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.3"
}
}
Complete console stacktrace:
Uncaught Error: The N-API version of this Node instance is 1. This module supports N-API version(s) 3. This Node instance cannot run this module.
at Object.module.exports.validate_package_json (/home/fabian/projects/prelude-pos/node_modules/node-pre-gyp/lib/util/napi.js:82:9)
at Object.validate_config (/home/fabian/projects/prelude-pos/node_modules/node-pre-gyp/lib/util/versioning.js:229:10)
at Object.exports.find (/home/fabian/projects/prelude-pos/node_modules/node-pre-gyp/lib/pre-binding.js:21:15)
at Object.<anonymous> (/home/fabian/projects/prelude-pos/node_modules/bcrypt/bcrypt.js:5:27)
at Object.<anonymous> (/home/fabian/projects/prelude-pos/node_modules/bcrypt/bcrypt.js:238:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at eval (webpack-internal:///bcrypt:1:18)
at Object.bcrypt (http://localhost:9080/renderer.js:2844:1)
at __webpack_require__ (http://localhost:9080/renderer.js:727:30)
at fn (http://localhost:9080/renderer.js:102:20)
So far, I wiped and reinstalled nodejs, cleared the node_modules and reinstalled all the packages, but no difference there.
So I found an answer to my own question in the end:
Electron comes bundled with its own version of nodejs apparently. Updating electron fixed my error.
Related
I've been having this issue with Jest. Jest is throwing an error pointing towards a dependency from within node_modules. Probably need to configure jest to support this syntax, because it can't parse it. But i'm not sure what for configurations.
I've tried to add transformIgnorePatterns in the jest.config.ts file with no luck,
"node_modules/(?!(geotiff)/)"
Any help would be highly appreciated!
Details:
/Users/Documents/Project/node_modules/quick-lru/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export default class QuickLRU extends Map {
^^^^^^
SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (node_modules/jest-cli/node_modules/jest-runtime/build/index.js:1796:14)
at Object.<anonymous> (node_modules/geotiff/dist-module/source/blockedsource.js:1:1)
This is the jest.config.ts
// jest.config.ts
import type {Config} from "#jest/types";
const config : Config.InitialOptions = {
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!**/*.d.ts"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"setupFilesAfterEnv": [
"<rootDir>/src/setupTests.ts"
],
"testMatch": [
"<rootDir>/src/**/*.(test).{js,jsx,ts,tsx}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}"
],
"testEnvironment": "node",
"testEnvironmentOptions": {
"url" : "http://localhost"
},
"transform": {
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "<rootDir>/config/jest/typescriptTransform.js",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
},
"transformIgnorePatterns": [
"node_modules/(?!(geotiff)/)"
],
"moduleFileExtensions": [
"web.ts",
"ts",
"web.tsx",
"tsx",
"web.js",
"js",
"web.jsx",
"jsx",
"json",
"node",
"mjs"
],
"globals": {
"ts-jest": {
"tsconfig": "./tsconfig.test.json"
}
},
"modulePaths": [
"<rootDir>/src/"
]
};
this is the package.json file
{
"name": "Project",
"version": "1",
"private": true,
"homepage": ".",
"files": [
"build/**/*"
],
"engines": {
"node": ">=16.14.0",
"npm": ">=8.11.0"
},
"repository": {
"type": "git",
"url": "ssh://Project},
"resolutions": {
"#types/react": "17.0.2",
"#types/react-dom": "17.0.2"
},
"scripts": {
"build-css": "sass --style=compressed -I ./src -I ./node_modules src/:src/",
"watch-css": "npm run build-css && sass -I ./src -I ./node_modules src/:/src --watch",
"start-js": "node scripts/start.js",
"start": "npm-run-all -p watch-css start-js",
"debug": "npm-run-all -p --inspect=9227 watch-css start-js",
"prebuild": "cross-env CI=true npm run test --watchAll=false",
"build": "npm run build-css && node scripts/build.js",
"postbuild": "node scripts/zip.js",
"build-test": "npm run build-css node scripts/build.js",
"serve-build": "npm run serve -s build",
"test": "node scripts/test.js --env=jsdom",
"prepublishOnly": "npm run build",
"preversion": "CI=true npm run test",
"postinstall": "patch-package",
"lint": "./node_modules/.bin/ESLint -c .eslintrc.js -o ./lint.log"
},
"devDependencies": {
"#babel/cli": "^7.18.6",
"#babel/core": "^7.18.6",
"#babel/preset-env": "^7.18.6",
"#babel/preset-react": "^7.18.6",
"#babel/preset-typescript": "^7.18.6",
"#babel/runtime": "^7.18.6",
"#svgr/webpack": "^6.2.1",
"#turf/turf": "^6.4.0",
"#types/classnames": "^2.3.1",
"#types/enzyme": "^3.10.12",
"#types/jest": "^28.1.3",
"#types/node": "^18.0.0",
"#types/react": "^17.0.39",
"#types/react-autocomplete": "^1.8.6",
"#types/react-autosuggest": "^10.1.5",
"#types/react-beautiful-dnd": "^13.1.2",
"#types/react-highlight": "^0.12.5",
"#types/react-router-dom": "^5.3.3",
"#types/uuid": "^8.3.4",
"#typescript-eslint/parser": "^5.30.0",
"#wojtekmaj/enzyme-adapter-react-17": "^0.6.7",
"adm-zip": "^0.5.9",
"autoprefixer": "10.4.7",
"awesome-typescript-loader": "^5.2.1",
"axios": "^0.27.2",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^28.1.1",
"babel-loader": "^8.2.2",
"babel-preset-react-app": "10.0.1",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"chalk": "5.0.1",
"classnames": "~2.2.6",
"core-js": "^3.6.5",
"cross-env": "^5.2.1",
"css-loader": "^6.7.1",
"dotenv": "16.0.1",
"enzyme": "^3.11.0",
"eslint": "^8.18.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jsdoc": "^39.3.3",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-react": "^7.22.0",
"eslint-webpack-plugin": "^3.2.0",
"file-loader": "^6.1.1",
"fork-ts-checker-webpack-plugin": "^7.2.11",
"fs-extra": "10.1.0",
"geotiff": "^2.0.5",
"html-webpack-injector": "^1.1.4",
"html-webpack-plugin": "^5.5.0",
"jest": "^28.1.1",
"jest-canvas-mock": "^2.4.0",
"jest-environment-jsdom": "^28.1.1",
"joi-browser": "^13.4.0",
"mini-css-extract-plugin": "^2.6.1",
"neo-async": "^2.6.2",
"npm-run-all": "^4.1.3",
"object-assign": "^4.1.1",
"ol": "~6.14.1",
"ol-ext": "^3.2.26",
"patch-package": "^6.2.2",
"proj4": "^2.5.0",
"promise": "^8.0.1",
"raf": "^3.4.0",
"react": "^17.0.2",
"react-app-polyfill": "^3.0.0",
"react-autocomplete": "^1.8.1",
"react-autosuggest": "^10.1.0",
"react-beautiful-dnd": "^13.1.0",
"react-dev-utils": "^12.0.0",
"react-docgen-typescript-webpack-plugin": "^1.1.0",
"react-dom": "^17.0.2",
"react-highlight": "^0.14.0",
"react-redux": "^8.0.2",
"react-scripts": "^5.0.0",
"redux": "^4.0.5",
"redux-mock-store": "^1.5.4",
"redux-thunk": "^2.3.0",
"resolve": "^1.6.0",
"sass": "^1.49.9",
"serve": "^13.0.2",
"sneakpeek-cli": "^0.2.1",
"source-map-loader": "^4.0.0",
"swiper": "^6.8.4",
"ts-jest": "^28.0.5",
"ts-loader": "^9.3.1",
"ts-node": "^10.8.1",
"tsconfig-paths-webpack-plugin": "^3.5.1",
"typescript": "^4.7.4",
"url-loader": "^4.1.1",
"uuid": "^7.0.3",
"webpack": "~5.73.0",
"webpack-dev-server": "^4.9.2",
"webpack-manifest-plugin": "^5.0.0"
},
}
Recently I update electron version from 9 to 10 and after updated getting this error on debug mode only
when I downgrade to 9 it's working correctly
Deleted Node_Module and package.lock file multiple times and reinstall all package but no luck
I tried to upgrade to 11 electrons also but facing the same issue
When I am running in production mode "Yarn Start" is working fine
The issue in dev mode only "Yarn dev"
ERROR:-
App threw an error during load Error: ENOENT: no such file or directory, open 'electron'
at Object.openSync (fs.js:462:3)
at Object.func [as openSync] (electron/js2c/asar.js:140:31)
at Object.readFileSync (fs.js:364:35)
at Object.fs.readFileSync (electron/js2c/asar.js:542:40)
at Module._extensions..js (internal/modules/cjs/loader.js:1165:22)
at Object.newLoader [as .js] (C:\SVN\mangocrossplatform\trunk\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:779:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
My Package.json File
{
"name": "mangoapps-messenger",
"productName": "Apps Messenger",
"version": "15.0.11",
"description": "Apps Messenger - An Universal Messenger For Apps",
"homepage": "",
"author": {
"email": "",
"name": ""
},
"scripts": {
"build": "yarn clean && concurrently \"yarn build-main\" \"yarn build-renderer\"",
"build-dll": "cross-env NODE_ENV=development webpack --config ./configs/webpack.config.renderer.dev.dll.babel.js --colors",
"build-main": "cross-env NODE_ENV=production webpack --config ./configs/webpack.config.main.prod.babel.js --colors",
"build-renderer": "cross-env NODE_ENV=production webpack --config ./configs/webpack.config.renderer.prod.babel.js --colors",
"dev": "yarn clean && cross-env START_HOT=1 node -r #babel/register ./internals/scripts/CheckPortInUse.js && cross-env START_HOT=1 yarn start-renderer-dev",
"package": "yarn build && electron-builder build --publish never",
"package-linux": "yarn build && electron-builder build --linux",
"package-mac": "yarn build && CSC_LINK=./certs/mac.p12 && CSC_IDENTITY_AUTO_DISCOVER=false && electron-builder build --mac",
"package-win": "yarn build && electron-builder build --win --x64",
"package-win32": "yarn build && electron-builder build --win --ia32",
"postinstall": "electron-builder install-app-deps && yarn build-dll && opencollective-postinstall",
"preinstall": "node ./internals/scripts/CheckYarn.js",
"prestart": "yarn build",
"start": "cross-env NODE_ENV=production electron ./dist/main.prod.js",
"start-main-dev": "cross-env HOT=1 NODE_ENV=development electron -r #babel/register ./app/main.dev.js",
"start-renderer-dev": "cross-env NODE_ENV=development webpack-dev-server --config configs/webpack.config.renderer.dev.babel.js",
"clean": "rimraf dist/"
},
"main": "./dist/main.prod.js",
"build": {
"productName": "Apps Messenger",
"appId": "com.mangoapps.electrondesktop",
"artifactName": "${name}-${version}.${ext}",
"generateUpdatesFilesForAllChannels": true,
"mac": {
"category": "productivity",
"type": "distribution",
"provisioningProfile": "certs/mac.provisionprofile",
"identity": "sdasdB",
"hardenedRuntime": true,
"entitlements": "build/entitlements.mac.inherit.plist",
"entitlementsInherit": "build/entitlements.mac.inherit.plist",
"gatekeeperAssess": false,
"extendInfo": {
"NSAppTransportSecurity": {
"NSAllowsArbitraryLoads": true,
"NSMicrophoneUsageDescription": "This lets you share using audio using the microphone.",
"NSCameraUsageDescription": "This lets you share a photo or video taken from your camera.",
"NSContactsUsageDescription": "This lets you enable access to your contacts and uses them to invite."
}
},
"target": [
"zip"
]
},
"linux": {
"target": [
"deb"
],
"category": "Productivity"
},
"win": {
"target": [
"nsis",
"msi"
],
"certificateFile": "",
"certificatePassword": "",
"publisherName": "",
"requestedExecutionLevel": "asInvoker",
"signAndEditExecutable": true,
"signDlls": true
},
"nsis": {
"oneClick": true,
"perMachine": false,
"deleteAppDataOnUninstall": true
},
"msi": {
"oneClick": true,
"perMachine": true
},
"files": [
"resources",
"dist/",
"dist/main.prod.js",
"dist/main.prod.js.map",
"package.json"
],
"directories": {
"buildResources": "resources",
"output": "release"
}
},
"keywords": [
"mangoapps",
"messenger"
],
"devDependencies": {
"#babel/core": "^7.4.0",
"#babel/plugin-proposal-class-properties": "^7.4.0",
"#babel/plugin-proposal-decorators": "^7.4.0",
"#babel/plugin-proposal-do-expressions": "^7.2.0",
"#babel/plugin-proposal-export-default-from": "^7.2.0",
"#babel/plugin-proposal-export-namespace-from": "^7.2.0",
"#babel/plugin-proposal-function-bind": "^7.2.0",
"#babel/plugin-proposal-function-sent": "^7.2.0",
"#babel/plugin-proposal-json-strings": "^7.2.0",
"#babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
"#babel/plugin-proposal-nullish-coalescing-operator": "^7.2.0",
"#babel/plugin-proposal-numeric-separator": "^7.2.0",
"#babel/plugin-proposal-optional-chaining": "^7.2.0",
"#babel/plugin-proposal-pipeline-operator": "^7.3.2",
"#babel/plugin-proposal-throw-expressions": "^7.2.0",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/plugin-syntax-import-meta": "^7.2.0",
"#babel/plugin-transform-react-constant-elements": "^7.2.0",
"#babel/plugin-transform-react-inline-elements": "^7.2.0",
"#babel/preset-env": "^7.4.2",
"#babel/preset-flow": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"#babel/register": "^7.4.0",
"#fortawesome/fontawesome-pro": "^5.12.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^24.5.0",
"babel-loader": "^8.0.5",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"babel-register": "^6.26.0",
"chalk": "^2.4.2",
"concurrently": "^4.1.0",
"cross-env": "^5.2.0",
"cross-spawn": "^6.0.5",
"css-loader": "2.1.1",
"detect-port": "^1.3.0",
"electron": "^10.0.0",
"electron-builder": "^22.9.1",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.11.2",
"enzyme-to-json": "^3.3.5",
"fbjs-scripts": "^1.2.0",
"file-loader": "^4.2.0",
"html-webpack-plugin": "^3.2.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^24.5.0",
"mini-css-extract-plugin": "^0.8.0",
"node-sass": "^4.13.0",
"opencollective-postinstall": "^2.0.2",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"prettier": "^1.16.4",
"react-svg-loader": "^3.0.3",
"react-test-renderer": "^16.8.6",
"redux-logger": "^3.0.6",
"rimraf": "^3.0.0",
"sass-loader": "^7.1.0",
"sinon": "^7.3.1",
"spectron": "^5.0.0",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.2.3",
"testcafe": "^1.1.0",
"testcafe-browser-provider-electron": "^0.0.8",
"testcafe-live": "^0.1.4",
"testcafe-react-selectors": "^3.1.0",
"url-loader": "^1.1.2",
"webpack": "^4.29.6",
"webpack-bundle-analyzer": "^3.1.0",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1",
"webpack-merge": "^4.2.1",
"yarn": "^1.16.0"
},
"dependencies": {
"#babel/polyfill": "^7.7.0",
"#fortawesome/fontawesome-svg-core": "^1.2.26",
"#fortawesome/free-solid-svg-icons": "^5.12.0",
"#fortawesome/pro-duotone-svg-icons": "^5.12.0",
"#fortawesome/pro-light-svg-icons": "^5.12.0",
"#fortawesome/pro-regular-svg-icons": "^5.12.0",
"#fortawesome/pro-solid-svg-icons": "^5.12.0",
"#fortawesome/react-fontawesome": "^0.1.8",
"#trodi/electron-splashscreen": "^0.3.4",
"app-root-path": "^2.2.1",
"axios": "^0.21.1",
"babel-runtime": "^6.26.0",
"bootstrap": "^4.3.1",
"check-internet-connected": "^2.0.4",
"connected-react-router": "^6.3.2",
"copy-webpack-plugin": "^5.1.1",
"core-js": "2",
"custom-electron-titlebar": "^3.2.2-hotfix62",
"devtron": "^1.4.0",
"dotenv": "^8.2.0",
"electron-debug": "^2.1.0",
"electron-dl": "^3.0.2",
"electron-fetch": "^1.3.0",
"electron-localshortcut": "^3.1.0",
"electron-log": "^4.1.1",
"electron-positioner": "^4.1.0",
"electron-splashscreen": "^0.1.7",
"electron-store": "^3.2.0",
"electron-unhandled": "^3.0.2",
"electron-util": "^0.14.1",
"electron-window-state": "^5.0.3",
"emoji-mart": "^2.11.1",
"form-data": "^2.3.3",
"fs-extra": "^8.1.0",
"jquery": "^3.3.1",
"js-md5": "^0.7.3",
"lodash": "^4.17.15",
"mime-types": "^2.1.27",
"moment-timezone": "^0.5.27",
"node-mac-notifier": "file:local_dep/node-mac-notifier",
"node-machine-id": "^1.1.12",
"node-notifier": "^8.0.0",
"platform-folders": "^0.4.1",
"plist": "^3.0.1",
"popper.js": "^1.15.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hot-loader": "^4.12.15",
"react-image-crop": "^8.4.0",
"react-lazyload": "^2.6.2",
"react-page-layout": "^0.9.8",
"react-phone-input-2": "^2.13.9",
"react-player": "^1.15.2",
"react-redux": "^7.2.0",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-select": "^3.0.3",
"react-tenor": "^2.1.1",
"react-toastify": "^6.0.8",
"reactstrap": "^8.5.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"source-map-support": "^0.5.11",
"styled-components": "^5.0.0",
"universal-analytics": "^0.4.23",
"xml2js": "^0.4.19",
"zip-folder": "^1.0.0"
},
"devEngines": {
"node": ">=12.13.0",
"npm": ">=6.12.0",
"yarn": ">=1.19.0"
},
"browserslist": [
"defaults"
]
}
Problem:
Trying npm run dev to start the server but it's giving following error although exactly same code is working fine for other team members.
Error:
Error: Cannot find module 'braintree'
Require stack:
- C:\Users\Zainulabideen\Documents\GitHub\wine\dist\routes\api\braintree\clientToken.js
- C:\Users\Zainulabideen\Documents\GitHub\wine\dist\app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\Zainulabideen\Documents\GitHub\wine\dist\routes\api\braintree\clientToken.js:5:17)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Zainulabideen\\Documents\\GitHub\\wine\\dist\\routes\\api\\braintree\\clientToken.js',
'C:\\Users\\Zainulabideen\\Documents\\GitHub\\wine\\dist\\app.js'
]
}
[nodemon] app crashed - waiting for file changes before starting...
Relevant Code:
app.js
....
const brainTreeToken = require("./routes/api/braintree/clientToken");
app.get("/client_token", function (req, res) {
brainTreeToken.braintreeClient(req, res);
});
....
clientToken.js
var braintree = require("braintree");
import { useDispatch } from "react-redux";
const braintreeClient = (req, res) => {
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "XXXXXXXXXXX",
publicKey: "XXXXXXXXXXXX",
privateKey: "XXXXXXXXXXX",
});
gateway.clientToken.generate({}, function(err, response) {
var clientToken = response.clientToken;
res.send(clientToken);
});
};
module.exports = {
braintreeClient: braintreeClient,
};
Package.json
{
"name": "XYZ",
"version": "0.0.10",
"private": true,
"description": "React APP",
"license": "ISC",
"author": "Temp",
"main": "index.js",
"scripts": {
"start": "node dist/app.js",
"start:prod": "npm i --production && npm run build && npm run server",
"dev": "echo Running App Under Watcher Nodemon Hot Deploy && nodemon dist/app.js",
"test": "jest --bail",
"test:watch": "jest --watch",
"build": "sh ./scripts/build-app.sh",
"build:dev": "SET NODE_ENV=development && npm run build",
"build:prod": "SET NODE_ENV=production npm run build",
"server": "node dist/app.js",
"server:dev": "SET NODE_ENV=development npm run server",
"server:prod": "SET NODE_ENV=production npm run server",
"docker": "sh ./scripts/build-docker.sh",
"webpack": "rimraf ./build && webpack --config tools/webpack.config.js",
"lint": "eslint src/**/*.js",
"hotstart": "nohup node src/server.js > nohup.out 2> nohup.err < /dev/null & react-scripts start"
},
"eslintConfig": {
"extends": "react-app"
},
"dependencies": {
"awesome-notifications": "^3.0.3",
"babel-eslint": "^10.0.2",
"body-parser": "^1.19.0",
"bootstrap": "^4.3.1",
"console-stamp": "^0.2.9",
"cookie-parser": "~1.4.3",
"cors": "^2.8.5",
"debug": "~2.6.9",
"eslint": "^6.0.1",
"eslint-config-react-app": "^4.0.1",
"eslint-loader": "^2.2.1",
"eslint-plugin-flowtype": "^3.11.1",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.2",
"express": "^4.17.1",
"express-session": "^1.16.2",
"fbemitter": "^2.1.1",
"font-awesome": "^4.7.0",
"http-errors": "~1.6.2",
"i18next": "^19.0.1",
"i18next-browser-languagedetector": "^4.0.1",
"i18next-xhr-backend": "^3.2.2",
"moment": "^2.24.0",
"morgan": "^1.9.1",
"nodemon": "^1.19.1",
"path": "^0.12.7",
"pem": "^1.14.2",
"prop-types": "^15.7.2",
"proxy": "^1.0.1",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0-beta.12",
"react-datepicker": "^2.9.6",
"react-dev-utils": "^9.0.1",
"react-dom": "^16.12.0",
"react-flexbox-grid": "^2.1.2",
"react-hooks-paginator": "^0.4.0",
"react-i18next": "^9.0.10",
"react-iframe": "^1.8.0",
"react-js-pagination": "^3.0.2",
"react-notifications-component": "^2.0.7",
"react-redux": "^7.1.1",
"react-router": "^5.0.1",
"react-router-dom": "^5.0.1",
"react-router-redux": "^4.0.8",
"react-scripts": "^3.3.1",
"react-select": "^3.0.8",
"react-spinners": "^0.6.1",
"react-switch": "^5.0.1",
"react-table": "^6.10.0",
"react-toastify": "^5.4.1",
"reactstrap": "^8.4.0",
"redux": "^4.0.4",
"redux-saga": "^1.1.1",
"request": "^2.88.2",
"simple-react-validator": "^1.2.2",
"socket.io": "^2.2.0",
"underscore": "^1.9.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"braintree-web": "^3.58.0",
"css-loader": "^3.2.0",
"eslint": "^6.5.0",
"eslint-config-prettier": "^6.3.0",
"eslint-config-react-app": "^4.0.1",
"eslint-loader": "^2.2.1",
"eslint-plugin-flowtype": "^3.11.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.7.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^4.3.0",
"html-webpack-plugin": "^3.2.0",
"jest": "^24.8.0",
"mini-css-extract-plugin": "^0.7.0",
"node-sass": "^4.13.1",
"paypal-checkout": "^4.0.311",
"prettier": "^1.18.2",
"puppeteer": "^1.17.0",
"rimraf": "^2.7.1",
"sass-loader": "^7.1.0",
"url-loader": "^2.0.0",
"webpack": "^4.34.0",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.7.1"
},
"nodemonConfig": {
"ext": "js, html, scss",
"ignore": [
"node_modules/*",
"build/*",
"dist/*",
"scripts/*",
".git"
],
"exec": "sh ./scripts/build-watch.sh"
}
}
Operating System and Terminal:
Windows 10, git bash
Approaches tried:
1) npm install
2) npm install --save-dev
3) Deleted node_modules folder again tried npm install
4) Deleted package-lock.json, node_modules folder and again tried npm install
5) Checked if particular is present in node_modules, it's present.
6) Using git-bash terminal, tried switching to cygwin terminal.
7) As using Windows, tried restarting machine. (Pardon, if it hurted you :( )
8) Verified folder structure, it's fine.
Note:
Codebase was working fine for before talking pull, after pull it's creating problem but it's working completely fine for other team members even after pull.
I don't see braintree in package.json, it is working in your team member's pc because they maybe installed it separately. Sometimes I tend to forget adding it to package.json when I develop a feature because it takes experimenting with bunch of packages so the package is in my node_modules folder already. Also there is a possibility that someone forgot to git add the package.json.
Anyway, To add to your package.json do and push,
npm i braintree --save
and push it after git add package.json
I'm integrating jest into my nuxt application using vue-test-utils (following Edd Yerburgh's new book).
The test fails right out of the box with "SyntaxError: Unexpected token {". Similar code builds fine with nuxt and the tests ran with Ava. I'm assuming that I have a problem with my jest configuration.
I've included my package.json, code excerpt and console out.
Thanks for any help,
Dan
npm 6.4.0
package.json
{
"name": "cxl-ui-base",
"version": "1.0.0",
"description": "Base UI for SA and CXL",
"author": "Dan Mahoney <dan.mahoney#contextlabs.com>",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"test:coverage": "TEST=unit nyc --report-dir=generated-files/coverage ava --tap | tap-summary",
"test:unit": "NODE_ENV=testing jest --verbose --no-cache",
"test:watch": "NODE_ENV=pro ava --watch",
"lint": "eslint -f node_modules/eslint-detailed-reporter/lib/detailed.js --ext .js,.vue -o generated-files/lint.html .",
"doc": "jsdoc -c doc.conf.js"
},
"dependencies": {
"#nuxtjs/auth": "^4.5.1",
"#nuxtjs/axios": "^5.3.1",
"#nuxtjs/dotenv": "^1.1.1",
"ava-describe": "^2.0.0",
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"dotenv": "^5.0.1",
"eslint-import-resolver-alias": "^1.1.1",
"express": "^4.16.3",
"jsdoc-vue": "^1.0.0",
"jsonwebtoken": "^8.2.1",
"leaflet": "^1.3.1",
"lodash": "^4.17.10",
"moment": "^2.22.1",
"npm": "^6.4.0",
"nuxt": "1.4.1",
"nuxt-leaflet": "0.0.10",
"nuxt-material-design-icons": "^1.0.4",
"oauth-1.0a": "^2.2.4",
"vue": "^2.5.16",
"vue-d3": "^0.1.0",
"vue-i18n": "^7.6.0",
"vue-uuid": "^1.0.0",
"vue2-leaflet": "^1.0.2",
"vuelidate": "^0.7.2",
"vuetify": "^1.0.17",
"vuex": "^3.0.1",
"webpack-node-externals": "^1.7.2"
},
"devDependencies": {
"#babel/core": "^7.0.0-rc.2",
"#vue/test-utils": "^1.0.0-beta.19",
"ajv": "^6.5.0",
"babel-eslint": "^7.2.3",
"babel-jest": "^23.4.2",
"babel-plugin-add-module-exports": "^0.3.3",
"babel-plugin-transform-imports": "^1.4.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1",
"babel-preset-vue-app": "^2.0.0",
"chromedriver": "^2.38.3",
"eslint": "^4.3.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-standard": "^10.2.1",
"eslint-detailed-reporter": "^0.7.3",
"eslint-import-resolver-webpack": "^0.9.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-html": "^4.0.3",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsdoc": "^3.7.1",
"eslint-plugin-leon-require-jsdoc": "0.0.1",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.1.0",
"eslint-plugin-vue": "^4.5.0",
"eslint-plugin-vue-a11y": "0.0.26",
"jest": "^23.5.0",
"jest-vue-preprocessor": "^1.4.0",
"jsdoc": "^3.5.5",
"jsdom": "^11.11.0",
"jsdom-global": "^3.0.2",
"loglevel": "^1.6.1",
"nightwatch": "^0.9.21",
"npm-merge-driver": "^2.3.5",
"raf": "^3.4.0",
"require-extension-hooks": "^0.3.2",
"require-extension-hooks-babel": "^0.1.1",
"require-extension-hooks-vue": "^1.0.0",
"selenium": "^2.20.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"tap-summary": "^4.0.0",
"vue-jest": "^2.6.0",
"vue-loader": "^13.7.2",
"vue-meta": "^1.5.0",
"vue-template-compiler": "^2.5.16"
},
"jest": {
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
}
},
"eslintConfig": {
"env": {
"browser": true,
"node": true,
"jest": true
}
}
}
Code
import { shallowMount, createLocalVue } from '#vue/test-utils';
import Vuetify from 'vuetify';
import test from 'jest';
import ClientMap from '#/components/Map'; // eslint-disable-line
import { commonAssertions } from '#/plugins/test.utils';
// for mocking
import modal from '#/components/Modal'; // eslint-disable-line
const localVue = createLocalVue();
localVue.use(Vuetify);
test('Sanity Test', () => {});
test('Initial State', (t) => {
const $modal = sinon.mock(modal);
const wrapper = shallowMount(Map, {
mocks: {
$modal,
},
localVue,
});
commonAssertions(Map, t, wrapper);
});
test.todo('Select Layer');
test.todo('Test Modal??');
test.todo('Test Tooltip??');
test.todo('UnSelect Layer');
Relevant Output
FAIL src/test/specs/map.spec.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/dan.mahoney/Projects/cxl-ui-base/src/test/specs/map.spec.js:10
import { shallowMount, createLocalVue } from '#vue/test-utils';
^
SyntaxError: Unexpected token {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.045s
The problem is that nuxt puts the babel config into nuxt.config.js. I found an npm package that solves that. It allows you to have a .babelrc file and have it injected into nuxt.config.js. When Jest compiles the files for testing, it uses .babelrc. Kudos to the author.
You should set the NODE_ENV to test then run the jest
you can do it by adding this line to your package.json file
"scripts": {
....
"test": "NODE_ENV=test jest"
},
I'm trying to compile my project with babel. I'm getting this error when tried to run (I'm using babel as some code contain ES6)
/usr/local/bin/node -r babel-register /Volumes/Elements/Learning/Node/Project/building-apis-with-nodejs-master/ntask-api/index.js
/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
throw e;
^
Error: Couldn't find preset "es2015" relative to directory "/Volumes/Elements/Learning/Node/Project/building-apis-with-nodejs-master/ntask-api"
at /Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (native)
at OptionManager.resolvePresets (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at compile (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-register/lib/node.js:103:45)
at loader (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-register/lib/node.js:144:14)
at Object.require.extensions.(anonymous function) [as .js] (/Volumes/Elements/Dev/Node.js/building-apis-with-nodejs-master/ntask-api/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:488:32)
Process finished with exit code 1
Here is my package.json
{
"name": "ntask-api",
"version": "1.0.0",
"description": "Task list API",
"main": "index.js",
"scripts": {
"start": "npm run apidoc",
"clusters": "babel-node clusters.js",
"test": "NODE_ENV=test mocha test/**/*.js",
"apidoc": "apidoc -i routes/ -o public/apidoc"
},
"apidoc": {
"name": "Node Task API - Documentation",
"template": {
"forceLanguage": "en"
}
},
"author": "Vic",
"dependencies": {
"bcrypt": "^0.8.5",
"body-parser": "^1.15.0",
"compression": "^1.6.1",
"consign": "^0.1.2",
"cors": "^2.7.1",
"express": "^4.13.4",
"helmet": "^1.1.0",
"jwt-simple": "^0.4.1",
"morgan": "^1.6.1",
"passport": "^0.3.2",
"passport-jwt": "^2.0.0",
"sequelize": "^3.19.2",
"sqlite3": "^3.1.1",
"winston": "^2.1.1"
},
"devDependencies": {
"apidoc": "^0.15.1",
"babel-cli": "^6.24.1",
"babel-preset-env": "^1.5.1",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.5.2",
"chai": "^3.5.0",
"mocha": "^2.4.5",
"supertest": "^1.2.0"
}
}
I have created my .babelrc
{
"presets": ["env","es2015"]
}
Anyone know what is wrong with the configuration? I'm using babel with express.js.