Cannot dockerize Prisma node mysql application #prisma/client did not initialize yet - node.js

I am having lots of trouble resolving this bug. I wrote a prisma nodejs application with react frontend and am ready to deploy. The app is working perfectly on my ubuntu system but everytime i try to run
sudo docker-compose up --build
I run into the same error
app/node_modules/.prisma/client/index.js:3
throw new Error(
^
Error: #prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues
at new PrismaClient (/app/node_modules/.prisma/client/index.js:3:11)
at Object.<anonymous> (/app/build/decks.js:10:16)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Module.require (node:internal/modules/cjs/loader:1057:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/app/build/game.js:41:17)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
/app/node_modules/.prisma/client/index.js:3
throw new Error(
no matter what i try
this is my Dockerfile for my node application:
FROM node:16
WORKDIR /app
COPY package*.json ./
COPY prisma ./prisma/
COPY . .
RUN npm install
EXPOSE 8000
CMD [ "node", "build/server.js" ]
my .env
MYSQL_HOST="localhost"
MYSQL_USER="game"
MYSQL_NAME="mygame"
MYSQL_PASS="mypassword"
MYSQL_ROOT_PASSWORD=mynewpassword
DB_URL="mysql://game:mypassword#localhost:3307/mygame"
DB_LOCAL_PORT=3307
DB_DOCKER_PORT=3308
NODE_LOCAL_PORT=8000
NODE_DOCKER_PORT=8000
and my package.json
{
"name": "nodejsin30min",
"version": "1.0.0",
"description": "",
"main": "./src/server.ts",
"scripts": {
"generate": "npx prisma generate",
"deploy": "npx prisma migrate deploy",
"devStart": "nodemon ./src/server.ts",
"test": "jest",
"build": "tsc -p",
"postinstall": "prisma generate"
},
"prisma": {
"schema": "./prisma/schema.prisma"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#prisma/client": "^4.6.1",
"#socket.io/admin-ui": "^0.2.0",
"#types/jest": "^28.1.7",
"#types/mocha": "^9.1.1",
"bcrypt": "^5.1.0",
"bcrypt-helper": "^0.2.1",
"body-parser": "^1.20.1",
"chroma": "^0.0.1",
"circular-json": "^0.5.9",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.17.1",
"express-jwt": "^7.7.7",
"express-oauth2-jwt-bearer": "^1.2.0",
"express-openid-connect": "^2.9.0",
"express-rate-limit": "^6.7.0",
"flatted": "^3.2.5",
"jwks-rsa": "^2.1.5",
"knex": "^2.3.0",
"mysql": "^2.18.1",
"mysql2": "^2.3.3",
"prisma": "^4.6.1",
"socket.io": "^4.4.0",
"socket.io-client": "^4.4.0",
"sqlite3": "^5.0.9",
"typesync": "^0.9.2",
"underscore": "^1.13.1",
"webpack": "^5.74.0"
},
"devDependencies": {
"#prisma/client": "^4.6.1",
"#types/express": "^4.17.13",
"#types/express-jwt": "^7.4.2",
"#types/jest": "^28.1.7",
"#types/mocha": "^9.1.1",
"#types/mysql": "^2.15.21",
"#types/node": "^18.7.7",
"#types/underscore": "^1.11.4",
"jest": "^27.4.3",
"nodemon": "^2.0.15",
"prisma": "^4.6.1",
"ts-node": "^10.9.1",
"typescript": "^4.4.3"
}
}
As you can see I already tried implementing a posinstall script with no luck. I have already tried shifting around multiple prisma commands (migrate dev, migrate deploy, generate) into every possible position of my Dockerfile with no luck - always the same error. On my device I NEVER had to manually generate a client and before i implemented prisma the application could be built just fine. I have no more ideas what to look for.
any help is appreciated.
Furthermore i habe already tried leaving out enironment variables and instead hardcoding the values, which did not work either
I also tried running RUN npm i -g prisma befor a prisma generate in my Dockerfile

Related

I re-installed node_modules in Nuxt.js and suddenly Must use import to load ES Module:~ appeared

When I re-installed node_modules, I was suddenly told that ufo and node-fetch were missing. After adding them, I ran npm run dev and opened localhost in a browser and encountered this error.
This error also occurred when I cloned this project on another laptop, and I am at a loss as to how to fix it.
I tried to solve the problem by myself as much as possible, but I couldn't find a solution because the stackframe was somehow Missing stack frames and this error itself is an error in the library. I'm not very familiar with tack overflow questions, so please let me know if you find any problems.
error
Must use import to load ES Module: C:\Users\Cou\Documents\就職関係\job_portfolio\nuxt_main\node_modules\.pnpm\node-fetch#3.2.6\node_modules\node-fetch\src\index.js require() of ES modules is not supported. require() of C:\Users\Cou\Documents\就職関係\job_portfolio\nuxt_main\node_modules\.pnpm\node-fetch#3.2.6\node_modules\node-fetch\src\index.js from C:\Users\Cou\Documents\就職関係\job_portfolio\nuxt_main\node_modules\.pnpm\vue-server-renderer#2.6.14\node_modules\vue-server-renderer\build.dev.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\Cou\Documents\就職関係\job_portfolio\nuxt_main\node_modules\.pnpm\node-fetch#3.2.6\node_modules\node-fetch\package.json.
Stack frames
internal/modules/cjs/loader.js:1089:13
Module._extensions..js
internal/modules/cjs/loader.js:937:32
Module.load
internal/modules/cjs/loader.js:778:12
Module._load
internal/modules/cjs/loader.js:961:19
Module.require
internal/modules/cjs/helpers.js:92:18
require
webpack:/external "node-fetch":1:
Object.node-fetch
webpack/bootstrap:25:
__webpack_require__
.nuxt/server.js:1:
Module../.nuxt/server.js
webpack/bootstrap:25:
__webpack_require__
package.json
{
"name": "nuxt_main",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint:style": "stylelint \"**/*.{css,scss,sass,html,vue}\" --ignore-path .gitignore",
"lint:prettier": "prettier --check .",
"lint": "npm run lint:js && npm run lint:style && npm run lint:prettier",
"lintfix": "prettier --write --list-different . && npm run lint:js -- --fix && npm run lint:style -- --fix",
"prepare": "husky install",
"test": "jest"
},
"lint-staged": {
"*.{js,vue}": "eslint --cache",
"*.{css,scss,sass,html,vue}": "stylelint",
"*.**": "prettier --check --ignore-unknown"
},
"dependencies": {
"#mdi/js": "^6.7.96",
"#nuxtjs/axios": "^5.13.6",
"core-js": "^3.19.3",
"csv-loader": "^3.0.3",
"csv-parse": "^5.2.0",
"fs": "0.0.1-security",
"node-fetch": "^3.2.6",
"nuxt": "^2.15.8",
"pnpm": "^7.4.0",
"ufo": "^0.8.4",
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"vuetify": "^2.6.1",
"webpack": "^4.46.0"
},
"devDependencies": {
"#babel/eslint-parser": "^7.16.3",
"#nuxtjs/eslint-config": "^8.0.0",
"#nuxtjs/eslint-module": "^3.0.2",
"#nuxtjs/stylelint-module": "^4.1.0",
"#nuxtjs/vercel-builder": "^0.22.1",
"#nuxtjs/vuetify": "^1.12.3",
"#vue/test-utils": "^1.3.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^27.4.4",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-nuxt": "^3.1.0",
"eslint-plugin-vue": "^8.2.0",
"husky": "^7.0.4",
"jest": "^27.4.4",
"lint-staged": "^12.1.2",
"postcss-html": "^1.3.0",
"prettier": "^2.5.1",
"stylelint": "^14.1.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended-vue": "^1.1.0",
"stylelint-config-standard": "^24.0.0",
"vue-jest": "^3.0.4"
}
}
OS: Windows
Node: v14.17.4
Apparently it was due to pnpm not being able to install all the required packages.
Running pnpm install followed by npm install (or yarn install) solved the problem.

Why aws app runner looks trying to build packages on node 12 even if node 14 is selected?

I'm trying to generate a build of our Next.js application that is on a Github repository. We used node 14.19.3 to build the application, and it runs fine on local development.
The package.json of main project is
{
"name": "example-name",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"#apollo/client": "^3.6.4",
"graphql": "^16.5.0",
"#our-private-package": "^1.0.7",
"framer-motion": "^2.9.4",
"i18next": "^21.8.0",
"js-cookie": "^2.2.1",
"next": "^12.1.6",
"next-cookies": "^2.0.3",
"ni18n": "^1.0.3",
"prop-types": "^15.7.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-ga": "^3.3.0",
"react-i18next": "^11.16.9",
"react-icons": "^4.3.1",
"react-modal": "^3.11.2",
"react-redux": "^7.2.1",
"react-slick": "^0.27.11",
"react-slider": "^2.0.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"sass": "^1.26.11",
"slick-carousel": "^1.8.1"
},
"devDependencies": {
"#ermeschultz/chai-arrays": "^2.3.0",
"chai": "^4.2.0",
"eslint": "^7.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.0.0",
"esm": "^3.2.25",
"file-loader": "^6.1.0",
"mocha": "^8.1.3",
"prettier": "^2.1.1",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"url-loader": "^4.1.0"
}
}
Our private package have this package.json file:
{
"name": "#our-private-package",
"version": "1.0.7",
...
"engines": {
"yarn": ">=1.22.0",
"npm": ">=6.14.16",
"node": ">=14"
},
"scripts": {
"prepare": "npm run build",
"start": "node ./build/index.js",
"dev": "ts-node ./src/index.ts",
"build": "tsc --module commonjs"
},
"dependencies": {
"canvas": "^2.9.1",
"canvas-5-polyfill": "^0.1.5"
},
"devDependencies": {
"#types/node": "^17.0.33",
"#types/react": "^17.0.39",
"#types/react-dom": "^17.0.3",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
},
"peerDependencies": {
"react": "^17.0.0",
"react-dom": "^17.0.0"
}
}
To create the service, I selected nodejs 14 platform and put these build commands in the app runner user interface:
export VARIABLE=value; npm install; npm run build
*The variable is an env variable necessary to import some private packages.
And this running commands in the app runner user interface:
npm start
The build logs show the message:
"[Build] \u001b[0m\u001b[91mError: The module '/app/node_modules/canvas/build/Release/canvas.node'\n",
"[Build] was compiled against a different Node.js version using\n",
"[Build] NODE_MODULE_VERSION 72. This version of Node.js requires\n",
"[Build] NODE_MODULE_VERSION 83. Please try re-compiling or re-installing\n",
I removed the private package and then project builds successfully on app runner. But I just can't reproduce the same problem on my local machine.
The error on message was reported previously on Stack Overflow, always relating to the use of another version of node than the current used one. It is always solved by reinstalling, rebuilding, and/or clearing the npm cache. But app runner creates the container from scratch.
The interface shows that we are using Node js 14 environment. But it seems running on the Node js 12 platform when running npm run build command. At least for the canvas module build.
It could be a package conflict case. But, why this shows the message like it was build in node 12? Why the same problem does not happens in my local development even if I'm using same node and npm present in App Runner?
It is not a definitive complete answer to the question, but run yarn install; yarn build instead npm make the same code runs on app runner.

How to fix: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js

I am trying to run a typescript express.js in a docker container. After running the docker I get the following error:
> ts-node-dev src/app.ts
Using ts-node version 8.10.1, typescript version 3.9.2
TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
at Object.watch (fs.js:1441:11)
at add (/app/node_modules/filewatcher/index.js:74:34)
at /app/node_modules/filewatcher/index.js:93:5
at FSReqCallback.oncomplete (fs.js:176:5)
my Dockerfile:
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm","start"]
and the package.json file:
{
"name": "app-name",
"version": "1.0.0",
"description": "Init master",
"main": "src/app.ts",
"scripts": {
"build": "./node_modules/.bin/tsc",
"start": "ts-node-dev src/app.ts"
},
"repository": {
"type": "git",
"url": "https://*****#dev.azure.com/********"
},
"author": "",
"license": "ISC",
"dependencies": {
"celebrate": "^12.1.1",
"colors": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"event-dispatch": "^0.4.1",
"eventemitter3": "^4.0.0",
"express": "^4.17.1",
"helmet": "^3.22.0",
"jsonwebtoken": "^8.5.1",
"moment": "^2.25.3",
"mongoose": "^5.9.13",
"morgan": "^1.10.0",
"ms": "^2.1.2",
"pbkdf2": "^3.0.17",
"redis": "^3.0.2",
"reflect-metadata": "^0.1.13",
"status-code-enum": "^1.0.0",
"swagger-jsdoc": "^4.0.0",
"swagger-ui-express": "^4.1.4",
"ts-node": "^8.10.1",
"typedi": "^0.8.0",
"uuid": "^8.0.0",
"winston": "^3.2.1"
},
"devDependencies": {
"#types/express": "^4.17.6",
"#types/mongoose": "^5.7.16",
"#types/node": "^13.13.5",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.8.3"
}
}
P.S. I have decided to include the fix:
change the Dockerfile:
FROM node:lts-alpine
and change the package.json:
"start": "ts-node-dev src/app.ts --poll"
Node v14 introduced a breaking change to the fs.watch() API, specifically that the recursive option (which has never been supported on Linux) now raises the ERR_FEATURE_UNAVAILABLE_ON_PLATFORM error if used on Linux.
A bug report and fix have been submitted to filewatcher: https://github.com/fgnass/filewatcher/pull/6
Until that fix is merged and a new version released, you'll need to stick to NodeJS < v14, or override the filewatcher package installed locally to include that patch.
It seems this error caused by node.js v14, to fix it use this command:
ts-node-dev --poll src/app.ts
Or you can use another version of node.js rather than version 14

My sequelize-auto command execution throws error "Please install tedious package manually"

I have too many tables in my SQL server database and my application uses sequelize ORM of node.js.
I find out that there is a way to scaffold my database models and it is sequelize-auto command.
So I created a command and run it. but it throws an error!
here is my sequelize-auto command:
sequelize-auto -h my server_ip_address -d database_name -u username -x mypassword --dialect mssql -c ./api/config/onlinestore.json -o ./api/models/newScafolded
but when I run this command it throws this error:
C:\Users\AMoha\AppData\Roaming\npm\node_modules\sequelize-auto\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:21
throw new Error('Please install tedious package manually');
^
Error: Please install tedious package manually
at new ConnectionManager (C:\Users\AMoha\AppData\Roaming\npm\node_modules\sequelize-auto\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:21:13)
at new MssqlDialect (C:\Users\AMoha\AppData\Roaming\npm\node_modules\sequelize-auto\node_modules\sequelize\lib\dialects\mssql\index.js:12:28)
at new Sequelize (C:\Users\AMoha\AppData\Roaming\npm\node_modules\sequelize-auto\node_modules\sequelize\lib\sequelize.js:233:18)
at new AutoSequelize (C:\Users\AMoha\AppData\Roaming\npm\node_modules\sequelize-auto\lib\index.js:19:22)
at Object.<anonymous> (C:\Users\AMoha\AppData\Roaming\npm\node_modules\sequelize-auto\bin\sequelize-auto:90:12)
at Module._compile (internal/modules/cjs/loader.js:945:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
at Module.load (internal/modules/cjs/loader.js:798:32)
at Function.Module._load (internal/modules/cjs/loader.js:711:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
at internal/main/run_main_module.js:17:11
I installed and used tedious package.
here is my package.json content:
{
"name": "onlinestore",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "babel-watch ./bin/www",
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "^1.19.0",
"braces": "^3.0.2",
"constantinople": "^4.0.1",
"cookie-parser": "~1.3.3",
"cors": "^2.8.5",
"custom-env": "^1.0.0",
"debug": "^4.1.0",
"express": "^4.16.4",
"express-jwt": "^3.4.0",
"jade": "~1.9.1",
"jsonwebtoken": "^5.7.0",
"lodash": "^4.17.15",
"mongoose": "^5.8.7",
"morgan": "^1.9.1",
"passport": "^0.2.2",
"passport-local": "^1.0.0",
"sequelize": "^5.21.5",
"serve-favicon": "^2.5.0",
"tedious": "^6.7.0",
"uglify-js": "^3.4.9"
},
"devDependencies": {
"#babel/cli": "^7.4.4",
"#babel/core": "^7.4.4",
"#babel/preset-env": "^7.4.4",
"babel-watch": "^7.0.0",
"gulp": "^4.0.0",
"gulp-concat": "^2.6.0",
"gulp-ng-annotate": "^1.1.0",
"gulp-ng-html2js": "^0.2.3",
"gulp-sourcemaps": "^1.5.2",
"gulp-uglify": "^1.2.0",
"gulp-watch": "^5.0.1"
}
}
What's your idea?
Finally I found the solution.
I should install tedious and mssql package in the same path.
I run below command and my problem solved:
npm install -g mssql tedious
I searched again and finally I found overall solution.
A GUI Desktop App for export sequelize models from database automatically. click here to see what it will do. I used it and it worked for me.

When I try to use Parcel to build a production version of a React app that works fine in development mode, I get "Cannot find module 'sass'"

I've built a simple React/Redux app and am using Parcel for the bundler. It works fine in development mode, that is, using the script
"dev": "parcel ./src/index.html",
but when I tried to do
"build": "parcel build ./src/index.html",
I got the following error
/Users/abc/Documents/Projects/sandbox/smart/src/styles/main.scss: Cannot find module 'sass' from '/Users/abc/Documents/Projects/sandbox/smart/src/styles'
at /Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:97:35
at processDirs (/Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:244:39)
at isdir (/Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:251:32)
at /Users/abc/Documents/Projects/sandbox/smart/node_modules/resolve/lib/async.js:23:69
at FSReqWrap.oncomplete (fs.js:152:21)
This is the first time I've tried to build an app using Parcel and I'm lost. I'm using node-sass to import my sass files directly -- perhaps this has something to do with that.
The referenced file (main.scss) is referenced in App.js like this
import "../../styles/main.scss";
and is the first sass file to be included (App is loaded into the DOM like this in index.js:
const store = configureStore()
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
)
This is running under Node 11.15. My package.json follows -- any hints or help much appreciated!
{
"name": "friender",
"version": "1.0.0",
"description": "",
"main": "index.js",
"jest": {
"setupFiles": ["jest-localstorage-mock"]
},
"scripts": {
"dev": "parcel ./src/index.html",
"build": "parcel build ./src/index.html",
"lint": "eslint \"src/**/*.{js,jsx}\" --quiet",
"test": "jest"
},
"prettier": {
"semi": false
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"#babel/cli": "^7.6.0",
"#babel/core": "^7.6.0",
"#babel/plugin-transform-runtime": "^7.5.5",
"#babel/preset-env": "^7.6.0",
"#types/jest": "^24.0.18",
"babel-eslint": "^10.0.3",
"babel-preset-react": "^7.0.0-beta.3",
"eslint": "^6.2.2",
"eslint-config-prettier": "^6.1.0",
"jest": "^24.9.0",
"jest-localstorage-mock": "^2.4.0",
"parcel-bundler": "^1.12.3",
"prettier": "^1.18.2"
},
"dependencies": {
"#emotion/babel-preset-css-prop": "^10.0.14",
"#emotion/core": "^10.0.16",
"#emotion/styled": "^10.0.15",
"#fortawesome/fontawesome-svg-core": "^1.2.0-7",
"#fortawesome/free-solid-svg-icons": "^5.11.1",
"#fortawesome/react-fontawesome": "^0.1.4",
"axios": "^0.19.0",
"bulma": "^0.7.5",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-react": "^7.14.3",
"immer": "^4.0.0",
"node-sass": "^4.12.0",
"prop-types": "^15.7.2",
"react": "16.x",
"react-detect-offline": "^2.4.0",
"react-dom": "^16.9.0",
"react-fontawesome": "^1.6.1",
"react-modal": "^3.10.1",
"react-redux": "^7.1.1",
"redux": "^4.0.4",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0"
}
}
Try instead per the documentation for SCSS and error Cannot find module 'sass' use module sass instead of node-sass:
npm install -D sass
The documentation mentions being able to use node-sass, but there are several active issues with node-sass. Module sass may help resolve the error and allow you use SCSS in your application.
Hopefully that helps!

Resources