I created a Electron.js project like that :
install node 14
install vue-cli
create template project vue with : vue create myproject
install electron wrapper like this : vue add electron builder
install better-sqlite3 library
And when I run this command : npm run electron:serve
I have an error into inspect of browser electron like this :
Uncaught TypeError: Cannot read property 'modules' of undefined
at Object.eval (bindings.js?dfc1:29)
at eval (bindings.js:223)
at Object../node_modules/bindings/bindings.js (chunk-vendors.js:142)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (database.js?4c26:9)
at Object../node_modules/better-sqlite3/lib/database.js (chunk-vendors.js:59)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (index.js?f4f1:2)
and if I enter into bindings.js code I can find where is the error :
nodePreGyp:
'node-v' +
process.versions.modules** +
The loader of this file don't know process env variable of nodejs.
Why node js doesn't knowing it's process variable, it's strange ?
If Electron to do well to start browser, the issue is around the renderer process ?
But it seems to be better-sqlite3 module is concerned because error start with loading this library with webpack ?
there is my package.json file :
{
"name": "electron-project",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"#types/better-sqlite3": "^5.4.1",
"better-sqlite3": "^7.1.1",
"core-js": "^3.6.5",
"node-sass": "4.14.1",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"#types/chai": "^4.2.11",
"#types/electron-devtools-installer": "^2.2.0",
"#types/mocha": "^5.2.4",
"#typescript-eslint/eslint-plugin": "^2.33.0",
"#typescript-eslint/parser": "^2.33.0",
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-e2e-cypress": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-router": "~4.5.0",
"#vue/cli-plugin-typescript": "~4.5.0",
"#vue/cli-plugin-unit-mocha": "~4.5.0",
"#vue/cli-plugin-vuex": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/eslint-config-typescript": "^5.0.2",
"#vue/test-utils": "^1.0.3",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"electron": "^9.0.0",
"electron-devtools-installer": "^3.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass-loader": "^8.0.2",
"spectron": "11.0.0",
"typescript": "~3.9.3",
"vue-cli-plugin-electron-builder": "~2.0.0-rc.5",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"#vue/typescript/recommended"
],
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {},
"overrides": [
{
"files": [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)"
],
"env": {
"mocha": true
}
}
]
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
If I comment code line with import better-sqlite3 I don't have the issue.
Can you tell me where is the problem or help me to more understand how fix this...
Thank you
This issue has an origin from webpack auto managed by vue cli.
If you want to use better-sqlite3 library (or for similar issue) with vue and loading your project with webpack WRAPPED by vue into vue-cli, you need to add this into the vue.config.js
configureWebpack: {
externals: {
'better-sqlite3': 'commonjs better-sqlite3'
},
},
WARNING : you can use vue-cli and webpack without this specific file into your project because vue-cli managed that for you. But if you want to more customize vue-cli you need to add manually this file (which merged with the base vue.config.js that hidden by vue-cli).
Related
I'm getting the following error in my react project:
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
React 2
useTheme useTheme.js:4
useTheme useThemeWithoutDefault.js:9
useTheme useTheme.js:7
Box createBox.js:22
React 17
js index.js:8
factory react refresh:6
Webpack 3
react.development.js:1447
React 2
useTheme useTheme.js:4
useTheme useThemeWithoutDefault.js:9
useTheme useTheme.js:7
Box createBox.js:22
React 17
js index.js:8
factory react refresh:6
Webpack 3
__webpack_require__
<anonymous>
<anonymous>
The project consists of 2 separate parts, Components and Onboarding. Onboarding uses Components as a dependency.
Inside Components, I have 2 package.json files, one in the root and one in src.
Root package.json:
{
"name": "My Project",
"version": "2.0.0",
"description": "Main React Library",
"main": "dist/index.js",
"module": "dist/index.js",
"bundleDependencies": false,
"deprecated": false,
"license": "MIT",
"private": true,
"sideEffects": false,
"scripts": {
"build": "rm -rf dist && NODE_ENV=production babel src --out-dir dist --copy-files"
},
"devDependencies": {
"#babel/cli": "^7.18.10",
"#babel/core": "^7.18.10",
"#babel/plugin-syntax-flow": "^7.18.6",
"#babel/polyfill": "^7.12.1",
"#babel/preset-env": "^7.18.10",
"#babel/preset-flow": "^7.18.6",
"#babel/preset-react": "^7.18.6",
"#types/node": "^18.7.15",
"typescript": "^4.8.2",
"reactstrap": "^9.1.4",
"react-quill": "^2.0.0"
},
"dependencies": {}
}
package.json inside src:
{
"name": "My Project",
"version": "2.0.0",
"description": "Main React Library",
"main": "index.js",
"module": "index.js",
"bundleDependencies": false,
"deprecated": false,
"license": "MIT",
"private": true,
"sideEffects": false,
"dependencies": {
"#mui/icons-material": "5.4.1",
"#mui/material": "5.4.1",
"#mui/styled-engine": "5.4.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-router-dom": "6.2.1",
"axios": "^0.27.2",
"uuid": "^9.0.0",
"bootstrap": "^5.2.0"
}
}
Inside Onboarding, I also have 2 package.json files, one in the root and one in src:
Root package.json:
{
"name": "onboarding-ui",
"description": "",
"version": "0.1.0",
"scripts": {
"start": "sls offline --aws-profile",
"deploy": "sls deploy -s stage --aws-profile",
"test": "sls invoke test"
},
"devDependencies": {
"aws-sdk-mock": "^5.7.0",
"serverless": "^3.21.0",
"serverless-cloudfront-invalidate": "^1.11.0",
"serverless-latest-layer-version": "^2.1.1",
"serverless-mocha-plugin": "^1.12.0",
"serverless-offline": "^6.8.0",
"serverless-prune-plugin": "^1.4.3",
"serverless-s3-sync": "^1.14.4",
"serverless-scriptable-plugin": "^1.0.5"
}
}
package.json inside src:
{
"name": "onboarding",
"version": "0.2.17",
"private": true,
"author": "Me",
"license": "MIT",
"description": "presentation layer.",
"engines": {
"node": "14 || 15 || 16",
"npm": ">=6"
},
"dependencies": {
"#asseinfo/react-kanban": "2.2.0",
"#emotion/cache": "11.7.1",
"#emotion/react": "11.7.1",
"#emotion/styled": "11.6.0",
"#mui/icons-material": "5.4.1",
"#mui/material": "5.4.1",
"#mui/styled-engine": "5.4.1",
"#mui/styles": "^5.9.2",
"#react-jvectormap/core": "1.0.1",
"#react-jvectormap/world": "1.0.0",
"#testing-library/jest-dom": "5.16.2",
"#testing-library/react": "12.1.2",
"#testing-library/user-event": "13.5.0",
"accounted-ui": "../../Components/dist",
"axios": "^0.27.2",
"chart.js": "3.4.1",
"chroma-js": "2.4.2",
"crypto-js": "^4.1.1",
"dropzone": "5.9.2",
"flatpickr": "4.6.9",
"formik": "^2.2.9",
"html-react-parser": "1.4.8",
"i18next": "^21.9.1",
"i18next-browser-languagedetector": "^6.1.5",
"i18next-http-backend": "^1.4.1",
"lodash.debounce": "^4.0.8",
"prop-types": "15.8.1",
"react": "17.0.2",
"react-chartjs-2": "3.0.4",
"react-confetti": "^6.1.0",
"react-csv": "^2.2.2",
"react-debounce-input": "^3.3.0",
"react-dom": "17.0.2",
"react-flatpickr": "3.10.7",
"react-github-btn": "1.2.1",
"react-i18next": "^11.18.5",
"react-images-viewer": "1.7.1",
"react-quill": "1.3.5",
"react-router-dom": "6.2.1",
"react-scripts": "5.0.0",
"react-table": "7.7.0",
"react-toastify": "^9.0.3",
"stylis": "4.0.13",
"uuid": "8.3.2",
"web-vitals": "2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build:dev": "dotenv -e .env.dev react-scripts build",
"build:prod": "dotenv -e .env.prod react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"accounted-ui": "../../Components/dist", // this is how I'm pulling in the `Components` folder
"dotenv-cli": "^5.1.0",
"eslint": "8.8.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-react": "7.28.0",
"eslint-plugin-react-hooks": "4.3.0",
"prettier": "2.5.1"
}
}
The project is using Material UI, which I suspect might also have something to do with this. I tried many suggestions but nothing has worked so far. Would appreciate it if anyone can help with this.
I'm trying to build a react components library (e.g Buttons, Modals, etc.)
But until now I still cannot figure how to do nested imports
the objective that i want to have is to be able to do this
import Something from '#company/moduleName/Something'
here is my package.json
{
"name": "#company/moduleName",
"version": "1.0.0",
"description": "company's react design system",
"author": "",
"license": "",
"repository": "",
"main": "dist/index.js",
"module": "dist/index.modern.js",
"source": "src/index.js",
"engines": {
"node": ">=13",
"npm": ">=7"
},
"type": "module",
"exports": {
".": "./dist/index.modern.js",
"./Button": "./dist/Button.modern.js",
"./Container": "./dist/Container.modern.js",
"./Input": "./dist/Input.modern.js",
"./Modal": "./dist/Modal.modern.js",
"./Select": "./dist/Select.modern.js",
"./Separator": "./dist/Separator.modern.js",
"./Sidebar": "./dist/Sidebar.modern.js",
"./Tab": "./dist/Tab.modern.js",
"./TextArea": "./dist/TextArea.modern.js",
"./theme": "./dist/theme.modern.js",
"./Typography": "./dist/Typography.modern.js"
},
"scripts": {
"build": "microbundle src/*.js --no-compress --no-sourcemap -f modern,cjs",
"start": "microbundle src/*.js --no-compress --no-sourcemap -f modern,cjs watch",
"rename": "cd dist && ren *.modern.js *.js",
"prepare": "run-s build",
"test": "run-s test:unit test:lint test:build",
"test:build": "run-s build",
"test:lint": "eslint .",
"test:unit": "cross-env CI=1 react-scripts test --env=jsdom",
"test:watch": "react-scripts test --env=jsdom",
"predeploy": "cd example && npm install && npm run build",
"deploy": "gh-pages -d example/build"
},
"peerDependencies": {
"react": "^17.0.1",
"lodash.merge": "^4.6.2",
"react-icons": "^4.2.0",
"react-modal": "^3.12.1",
"react-select": "^4.1.0",
"styled-components": "^5.2.1"
},
"devDependencies": {
"babel-eslint": "^10.0.3",
"cross-env": "^7.0.2",
"env-cmd": "^10.1.0",
"eslint": "^7.21.0",
"eslint-config-prettier": "^6.7.0",
"eslint-config-standard": "^14.1.0",
"eslint-config-standard-react": "^9.2.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-standard": "^4.0.1",
"gh-pages": "^2.2.0",
"microbundle": "latest",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "^4.0.3",
"lodash.merge": "^4.6.2",
"react-icons": "^4.2.0",
"react-modal": "^3.12.1",
"react-select": "^4.1.0",
"styled-components": "^5.2.1"
},
"files": [
"dist"
],
}
currently i'm using microbundle to build everything in the src/ folder. I've added the exports field but it still says this in the example project inside the module
Module not found: Can't resolve '#company/moduleName/Button' in 'E:\Projects\Software\company\moduleName\example\src'
edit
To be clear, the dist folder shows up the correct desired result
-dist
index.modern.js
Modal.modern.js
...
I've also been able to do this, but this is not the desired output
#company/moduleName/dist/Something.modern
Any help would be greatly appreciated!
I'm working on Windows environment and trying to run a forked node.js + typescript project.
This is my package.json :
{
"name": "my-task",
"version": "1.0.0",
"private": true,
"main": "dist/main.js",
"scripts": {
"start": "tsc-watch --onSuccess 'node -r source-map-support/register .'",
"test": "jest",
"lint": "eslint --cache '{src,test}/**/*.ts'"
},
"dependencies": {
"#types/express": "^4.17.7",
"#types/node": "^12.12.53",
"express": "^4.17.1",
"get-port": "^5.1.1",
"got": "^11.5.1",
"source-map-support": "^0.5.19"
},
"devDependencies": {
"#types/jest": "^26.0.8",
"#typescript-eslint/eslint-plugin": "^3.8.0",
"#typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jest": "^23.20.0",
"jest": "^26.2.2",
"prettier": "^2.0.5",
"ts-jest": "^26.1.4",
"tsc-watch": "^4.2.9",
"typescript": "^4.0.2"
}
}
For some reason, i'm getting the following error:
error TS5023: Unknown compiler option '-r'.
I tried to remove the -r, but then i'm getting these errors:
error TS6054: File '.'' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6231: Could not resolve the path 'source-map-support/register' with the extensions: '.ts', '.tsx', '.d.ts'.
and server won't start.
I ran npm uninstall + npm install - nothing seems to solve these issues.
Can anyone assist?
EDITED:
ts.config:
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"]
}
I created a new project using vue-cli(#vue/cli 4.3.1). When there is an error in one of my component files(.vue file), in chrome console i do not see the actual file/line number. Instead i see a file reference called vue.runtime.esm.js?2b0e:619. Did some googling on how to enable source map. I added a vue.config.js file on my project root and added below lines:
module.exports = {
configureWebpack: (config) => {
config.devtool = 'eval-source-map'
},
productionSourceMap: true
};
Did npm run server. But still i do not see the actual file reference.
How do i enable source map in a vue-cli-project??
\\File: packages.json
{
"name": "real-world-vue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --mode development",
"lint": "vue-cli-service lint",
"build-watch": "vue-cli-service build-watch --mode development"
},
"dependencies": {
"axios": "^0.19.2",
"core-js": "^3.6.4",
"json-server": "^0.16.1",
"vue": "^2.6.11",
"vue-router": "^3.1.6",
"vuejs-datepicker": "^1.6.2",
"vuex": "^3.1.3"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.3.0",
"#vue/cli-plugin-eslint": "~4.3.0",
"#vue/cli-plugin-router": "~4.3.0",
"#vue/cli-plugin-vuex": "~4.3.0",
"#vue/cli-service": "~4.3.0",
"#vue/eslint-config-prettier": "^6.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-vue": "^6.2.2",
"node-sass": "^4.14.0",
"prettier": "^1.19.1",
"sass-loader": "^8.0.2",
"vue-cli-plugin-build-watch": "~1.0.0",
"vue-template-compiler": "^2.6.11"
}
}
Please help.
In my case I got it to work using devtool right under configureWebpack, so no config field there.
I also had to use 'cheap-module-source-map' instead of 'eval-source-map'. In the end it would look like this:
module.exports = {
configureWebpack: {
devtool: "cheap-module-source-map",
},
productionSourceMap: true
};
I updated all packages but still getting this error after running npm run serve:
Module build failed (from ./node_modules/eslint-loader/index.js):
Error: Cannot find module 'prettier' Occurred while linting /home
My package.json
{
"name": "app",
"version": "0.1.0",
"private": false,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.2.1",
"firebase": "^7.0.0",
"material-icons": "^0.3.1",
"register-service-worker": "^1.6.2",
"vue": "^2.6.10",
"vue-flickity": "^1.2.1",
"vue-router": "^3.1.3",
"vuetify": "^2.0.19",
"vuex": "^3.1.1"
},
"devDependencies": {
"#mdi/font": "^4.4.95",
"#vue/cli-plugin-babel": "^3.11.0",
"#vue/cli-plugin-eslint": "^3.11.0",
"#vue/cli-plugin-pwa": "^3.11.0",
"#vue/cli-service": "^3.11.0",
"#vue/eslint-config-prettier": "^5.0.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.4.0",
"eslint-plugin-vue": "^5.2.3",
"material-design-icons-iconfont": "^5.0.1",
"stylus": "^0.54.7",
"stylus-loader": "^3.0.2",
"uglifyjs-webpack-plugin": "^2.2.0",
"vue-cli-plugin-vuetify": "^0.6.3",
"vue-template-compiler": "^2.6.10",
"vuetify-loader": "^1.3.0",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"#vue/prettier"
],
"rules": {
"no-console": "off"
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
**"#vue/eslint-config-prettier": "^5.0.0",** is listed in the dependencies. How to fix this issue? (I'm using VSCODE on Ubuntu)
I tried multiple times deleting package-lock.json and node_modules and running npm install afterwards. Nothing fixes it - even updating all packages globally.
Prettier is a peer dependency of
#vue/eslint-config-prettier so you need to add it to your own dependencies:
npm install --save-dev prettier
With NPM
npm install --save-dev prettier
With Yarn
yarn add --dev prettier
if you're using yarn 3, and yarn add --dev prettier doesn't solve your problem, try this:
cmd + shift + p
in the dropdown, search for preferences: open user settings (json)
add "prettier.prettierPath": ".yarn/sdks/prettier/index.js" to your json file.
This tells your editor to find the module in the path you added.