I'm attempting to use the mikro-orm CLI but am getting a ts-node error:
$ npx mikro-orm debug
npx: installed 280 in 14.531s
(node:19228) UnhandledPromiseRejectionWarning: Error: Cannot find module 'ts-node'Require stack:
- C:\tmp\nodejs\npm-cache\_npx\19228\node_modules\mikro-orm\dist\cli\CLIHelper.js
- C:\tmp\nodejs\npm-cache\_npx\19228\node_modules\mikro-orm\dist\cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
at Function.Module._load (internal/modules/cjs/loader.js:923:27)
at Module.require (internal/modules/cjs/loader.js:1140:19)
at require (internal/modules/cjs/helpers.js:75:18)
My package.json has the following:
"scripts": {
"watch": "tsc -w",
"dev": "nodemon dist/index.js",
"start": "node dist/index.js",
"dev2": "nodemon --exec ts-node src/index.ts",
"start2": "ts-node src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1",
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#types/node": "^14.6.3",
"nodemon": "^2.0.4",
"ts-node": "^9.0.0",
"typescript": "^4.0.2"
},
"dependencies": {
"#mikro-orm/cli": "^4.0.0-alpha.0",
"#mikro-orm/core": "^4.0.0-alpha.0",
"#mikro-orm/migrations": "^4.0.0-alpha.0",
"#mikro-orm/postgresql": "^4.0.0-alpha.0",
"pg": "^8.3.3"
},
"mikro-orm": {
"useTsNode": true,
"configPaths": [
"./src/mikro-orm.config.ts",
"./dist/mikro-orm.config.js"
]
}
I'm using the 'watch' and 'dev' scripts to run currently, ts-node also works fine with the script 'start2'
My folder structure is: https://i.stack.imgur.com/7BGMT.png
This is new to me and I can't figure out what the problem is. Do you know what it could be?
Thank You!
answered by #MartinAdámek 'Upgrade all packages to latest version, you are on the very first alpha, latest is rc.6'
The real answer should be that your mikro-orm configuration inside package.json says useTsNode: true. Change it to false and it wont complain about missing ts-node.
Related
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"
}
}
First I'm trying to use this solution from Stack Overflow. I got everything to work except the last part when I try to watch the files. What I'm trying to accomplish is to watch for changes to my sass files and build a new style.css prefix and minify for each change and on save I can preview the changes in browser.
I would like to use only the npm, no Gulp or Grunt please.
{
"name": "name",
"version": "version",
"description": "",
"main": "index.js",
"scripts": {
"prebuild:css": "node-sass src/main.scss css/style.css ",
"build:css": "postcss --use autoprefixer -b 'last 2 versions' < css/style.css | postcss --use cssnano > css/style.min.css ",
"build": "npm run prebuild:css && npm run build:css ",
"watch": "watch 'npm run build' src/* "
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^10.2.5",
"cssnano": "^4.1.10",
"node-sass": "^5.0.0",
"postcss": "^8.2.8",
"postcss-cli": "^8.3.1",
"watch": "^1.0.2"
}
}
In your package.json file change the watch script to this:
"watch": "watch 'npm run build' './src'"
For some reason, electron-packager can't find the module electron. I have installed it as instructed from the official site, yet it doesn't seem to work. Here is what seems to happen, my package.json, and how I run electron-packager
Package.json
{
"name": "electron-part1",
"version": "1.0.0",
"description": "An electron tutorial",
"main": "index.js",
"jquery": "^3.3.1",
"scripts": {
"start": "electron .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Me",
"license": "ISC",
"devDependencies": {
"electron": "^5.0.3",
"electron-packager": "^8.7.2"
},
"dependencies": {
"custom-electron-titlebar": "^3.2.5",
"jquery": "^3.5.1"
}
}
What happens:
How I call electron-packager:
electron-packager . electron-part1 --platform=win32 --arch=x64
I fixed it! If anyone else is having the same problem, copy electron from %USERPROFILE%\AppData\Roaming\npm\node_modules, and paste it to node modules in your main folder (The one with package.json) then you can package it as normal
I just create a new react app using
create-react-app
and it worked as well , then I just cd into this app and tried
npm start
and then nothing worked & nothing appeared in the console
1- I have tried to remove node-module and then npm install again and try again
2- I tried to clean the cash and repeat step 1 and nothing worked
3- I tried to reinstall node and nothing worked ether .
that's my package.json file
{
"name": "ropofriend",
"version": "0.1.0",
"private": true,
"homepage": "https://kyrolos.github.io/Robofriend-app/.",
"dependencies": {
"gh-pages": "^2.0.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^5.1.1",
"react-scripts": "1.1.4",
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"tachyons": "^4.9.1"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
try this:
"start": "cd packages/react-scripts && node bin/react-scripts.js start",
basically you have to give the address of your main view file.
or this:
"start": "node src/feathers/"
I've got a sample react app I've been messing with to build out little small side projects. But I've hit a connundrum. Ctrl+C doesn't do anything to stop my app. I have to go through task manager manually to kill it. I've attached my package json. Is there some package or approach for this?
{
"name": "practice-app",
"description": "Sample react app to practice different designs, tools and concepts",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^1.2.2",
"#material-ui/icons": "^1.1.0",
"concurrently": "^3.6.0",
"json-server": "^0.14.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "concurrently \"react-scripts start\" \"json-server --watch data/db.json --port 3001\"",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3001"
}
maybe try writing an npm stop script?
"scripts": {
"start": "app.js",
"stop": "pkill --signal SIGINT myApp"
}
Hope that helps