Travis CI fails on tsc - javascript

So I have a typescript project hosted on github.
I'm trying to set up Travis CI for tests but when I get to the step to compile the code to javascript (tsc command) it fails.
The error looks like this:
> node node_modules/typescript/bin/tsc
src/DbHandler.ts:2:32 - error TS2307: Cannot find module './models/User'.
2 import { User, UserInit } from './models/User';
~~~~~~~~~~~~~~~
src/User.ts:2:22 - error TS2307: Cannot find module './models/User'.
2 import { User } from "./models/User";
~~~~~~~~~~~~~~~
Found 2 errors.
npm ERR! code ELIFECYCLE
The paths to the files ARE correct and it compiles just fine locally..
In the project I have this package.json(cleaned):
{
"name": "project",
"version": "0.0.1",
"description": "",
"main": "dist/server.js",
"scripts": {
"build": "node node_modules/typescript/bin/tsc",
"prod": "node dist/server.js",
"dev": "ts-node src/server.ts",
"dev:watch": "nodemon",
"test:watch": "ts-node node_modules/jasmine/bin/jasmine",
"test": "node node_modules/jasmine/bin/jasmine.js --config=jasmine.json"
},
"author": "myname",
"license": "MIT",
"devDependencies": {
"#types/express": "~4.17.1",
"#types/jasmine": "~3.4.4",
"jasmine": "~3.5.0",
"nodemon": "~1.19.4",
"ts-node": "~8.4.1",
"tslint": "~5.20.0",
"typescript": "~3.6.4"
},
"dependencies": {
"express": "~4.17.1"
}
}
And my .travis.yml looks like:
language: node_js
cache: npm
node_js:
- "stable"
install:
- npm ci
- npm run build
script:
- npm run test
And my file structure is something like this:
package.json
.travis.yml
src/
models/
User.ts
DbHandler.ts
User.ts
server.ts
test/
files_for_tests_with_ts_extension

Related

a dynamic link library (dll) initialization routine failed when build electron

error that when i run builded electron program
the program operate well in my computer but,when i build by 'electron-builder --win portable' and move to other computer then the error occured. (coding in window 11, test in window 10)
how do i fix it?
package.json
"scripts": {
"build:renderer": "webpack --config ./client/webpack.config.renderer.js",
"build:main": "tsc --project ./client/tsconfig.json",
"build": "npm run build:main && npm run build:renderer",
"build:addon:x86": "(cmake-js -G \"Visual Studio 16 2019\" -A Win32 -O build_Win32)",
"build:addon:x64": "(cmake-js -G \"Visual Studio 16 2019\" -A x64 -O build_x64)",
"start": "electron . --enable-logging",
"copy_binary": "copy_binary.bat",
"dist": "electron-builder --win portable"
},
"devDependencies": {
"cmake-js": "^7.0.0",
"electron-rebuild": "^3.2.7",
"ts-loader": "^9.4.1",
"typescript": "^3.1.0",
"webpack": "^5.74.0",
"electron": "16.0.10",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"node-addon-api": "^4.1.0"
},
"cmake-js": {
"runtime": "electron",
"runtimeVersion": "16.0.10"
}
i tried that...
add "postinstall": "electron-builder install-app-deps" in package.json
add set(DELAY_LOAD_HOOK "hook/win_delay_load_hook.cc") in cmakelists.txt
I managed to fix it copying the old binding.gyp file and ran electron-rebuild, the new .node file will be here .\electron-overlay\bin\win32-x64-109

Firebase Functions + monorepo - Deploying doesn't work + deps not installed locally

Looks like someone has the same problem here: https://github.com/firebase/firebase-functions/issues/1050
Problem
I have moved my project structure to a monorepo with the following structure:
/
|
| - node_modules/
|
| - packages/
| - - app/
| - - - - index.js
| - - - - package.json
| - - functions/
| - - - - src/
| - - - - - - helloWorld.function.js
| - - - - - - index.js
| - - - - package.json
|
| - .firebaserc
| - firebase.json
| - firestore.indexes.json
| - firestore.rules
| - package.json
| - yarn.lock
| - LICENSE.md
As far as I know, all code our functions depends on must be inside the functions directory. But... when I run yarn install, the node_modules of my functions are saved in the root node_modules folder.
Then, if I run firebase deploy from the root of my project, I get the error:
Error: Error occurred while parsing your function triggers.
The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
Note: I haven't made any code change... before configuring the project to the monorepo structure, everything worked fine.
My attempt to solve this problem
I have tried to use nohoist when defining my workspaces inside my root package.json:
{
"private": true,
"name": "#company/project",
"version": "1.0.0",
"description": "Project monorepo",
"repository": "...",
"license": "MIT",
"author": {
"name": "Raul",
"email": "...
},
"scripts": {
"app": "yarn workspace #company/app start",
"documentation": "yarn workspace #company/documentation start",
"server": "yarn workspace #company/server start"
},
"workspaces": {
"packages": ["packages/*"],
"nohoist": ["**/#company/server"] <---- HERE
}
}
-Note: when I run yarn server the functions shell is started correctly.
But... for some reason, after reinstalling everything:
rm -rf node_modules (everywhere)
yarn cache clean
yarn install
The dependencies of the functions packages are installed in the root node_modules!
Any ideas?
This is how my functions node_modules looks like after installing the deps:
node_modules/
.bin/
eslint
eslint-config-prettier
firebase-functions
functions-framework
functions-framework-nodejs
image_size
uuid
qs/
uuid/
And these are the dependencies required (which are installed in the root package.json, which is not the behavior I expect):
"name": "#company/server",
...
"dependencies": {
"#google-cloud/functions-framework": "^3.1.1",
"#google-cloud/translate": "^6.3.1",
"#google-cloud/vision": "^2.4.2",
"#googlemaps/google-maps-services-js": "^3.3.3",
"axios": "^0.27.2",
"camelcase": "^6.3.0",
"dotenv": "^16.0.1",
"expo-server-sdk": "^3.6.0",
"firebase-admin": "^10.3.0",
"firebase-functions": "^3.21.2",
"glob": "^7.2.0",
"image-size": "^1.0.1",
"lodash": "^4.17.21",
"moment": "^2.29.3",
"qs": "^6.10.3",
"sharp": "^0.30.6",
"uuid": "^8.3.2"
},
"devDependencies": {
"eslint": "^8.3.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^4.3.1",
"firebase-functions-test": "^0.2.0"
}
UPDATE
Instead of nohoisting in the root, I have placed this segment in the packages/functions/package.json:
workspaces: { nohoist: ["**"] }
and all the deps are installed locally!
But... when I do firebase deploy, same error. If instead of running the command from the root folder I do it from packages/functions/package.json the deployment is successful.
Why? What is happening?
This is my firebase.json file:
{
"functions": {
"predeploy": ["yarn --cwd \"$RESOURCE_DIR\" lint"],
"source": "packages/functions"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
}
}
Workaround (Not the correct solution, just a trick):
Instead of using nohoist to installing all the deps locally inside the packages/functions directory, what about excluding it from the yarn workspaces?
For this, update your root's package.json to:
"workspaces": [
"packages/app",
"packages/documentation"
]
(packages/functions is not included as a workspace.)
Test it:
Now, if you run (wherever you want in your project) firebase deploy, everything works fine... the deployment is successful and all our backend deps are installed locally (it is required, since all the cloud functions code must be inside the functions folder).
Also, this error is solved too!
Pros:
You can maintain the monorepository structure and deploy your cloud functions without problems.
Cons:
This is a tricky solution... when you run yarn install from the root of your project, packages/functions/package.json dependencies are not installed (as we have remove it from the workspace in order to install them locally.)
In order to solve this little issue, in your root package.json, write the following:
{
"scripts": {
...,
"postinstall": "cd path/to/your/functions && yarn install", // automatically executed after running `yarn install`
}
}
in my case:
{
"scripts": {
...,
"postinstall": "cd packages/functions && yarn install", // automatically executed after running `yarn install`
}
}

Editing package.js file

i'm having a hard time to understand how to run all of my .js files using package.js files
i have almost 2000.js scripts i need to run them one by one, i'm using a api made by gameflip
in the folder i found package.js, but i don't know how to use it ,
can anyone tell me how to do that ? thank you
here the script :
{
"name": "gfapi",
"version": "0.1.1",
"description": "Gameflip API",
"keywords": "Gameflip",
"homepage": "https://github.com/iJJi/gfapi",
"bugs": "https://github.com/iJJi/gfapi/issues",
"author": {
"name": "Eng-Shien Wu",
"email": "engshien.wu#ijji.com"
},
"license": "MIT",
"private": true,
"files": [
"index.js"
],
"repository": "iJJi/gfapi",
"engines": {
"node": ">=8.5.0"
},
"scripts": {
"bulk_listing": "node src/samples/bulk_listing.js",
"test": "ENVIRONMENT=mocha mocha src/test --recursive",
"docs": "jsdoc -c jsdoc_conf.js -d docs -P package.json index.js; docco -o docs/samples src/samples/*.js src/samples/*.rb"
},
"dependencies": {
"base-64": "^0.1.0",
"bluebird": "^3.5.0",
"bunyan": "^1.8.12",
"file-type": "^8.1.0",
"http-errors": "^1.6.2",
"node-rest-client-promise": "^3.1.1",
"promise-ratelimit": "^0.0.3",
"request": "^2.85.0",
"request-promise": "^4.2.2",
"speakeasy": "^2.0.0"
},
"devDependencies": {
"marked": "^0.3.19",
"docco": "^0.7.0",``
"jsdoc": "^3.5.5"
}
}
What you posted isn't a package.js (I don't even know if it exists), but a package.json. It's generated by NPM, the Node Package Manager. It's a list of all the project's dependencies. I think that what you're looking for are the npm scripts, they are in the script object of package.json.
npm run <script>
# For example :
npm run bulk_listing
npm run test
npm run docs
Each script will run its associated command in this package.json.
npm run bulk_listing
# Will do the same thing as:
node src/samples/bulk_listing.js
More about package.json.
The script I talked about below
If you want to run all the scripts, this should do the job :
const fileNames = ["path/to/fileA", "fileB"]; // I assume you have something to get all the files path. Isn't that npm run bulk_listing ?
fileNames.forEach(async (path, index) => {
// It's pretty much like 'node <path>'
await require(path);
// All the code here is executed AFTER the script has been launched
console.log(`LAUNCHED ${index} | ${path}`)
});

webpack + babel not bundling the js properly

I am using webpack and babel in my project. While the webpack is wokring fine but babel is somehow not doing it's job in polyfilling the ES6+ features. When I use the npm script, I get some error "Entrypoint undefined = index.html" in the command prompt. Kindly help !
Package.json
{
"name": "forkify",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"author": "neeraj",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.0.2",
"babel-preset-env": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.19.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"dependencies": {
"babel-polyfill": "^6.26.0"
}
}
webpack.config.js
const path=require('path');
const HtmlWebPackPlugin=require('html-webpack-plugin');
module.exports={
entry:['babel-polyfill','./src/js/index.js'],
output:{
path:path.resolve(__dirname,'dist'),
filename:'js/bundle.js'
},
devServer:{
contentBase:'./dist'
},
plugins:[
new HtmlWebPackPlugin({
filename:'index.html',
template:'./src/index.html'
})
],
module:{
rules:[
{
test:/\.js$/,
exclude:/node_modules/,
use:{
loader:'babel-loader'
}
}
]
}
};
.bablerc
{
"presets":[
["env",{
"targets":{
"browser":[
"last 5 versions",
"ie>=8"
]
}
}]
]
}
Error what I get:
Project Structure:
EDIT------------------
I started getting some new error now.
It is the html-webpack-plugin's problem, a fix was introduced in
3.0.7 but was removed again in 3.0.8. For more information, please click here.
So if you run npm install --save-dev html-webpack-plugin#3.0.7, and then npm run dev will output Entrypoint html-webpack-plugin for "index.html" = index.html. And personally, it is a trivail problem not that important.
There was some dependency issue. Deleted my node_modules folder and used this command instead: npm install -D babel-loader#7 babel-core babel-preset-env webpack
Follow this link for more information : https://github.com/babel/babel-loader
Now I no longer get any error and also babel is working fine.
FYI....you might have to install babel-polyfill & html-webpack-plugin seperately.

Browser Sync Error - 'Cannot GET/'

I'm currently using Browser Sync newest version (2.24.6) installed via npm install -g browser-sync and I did so in my C:\Users\USERNAME\Google Drive I am using Gulp.
I start browser sync by running browser-sync start --server --files '*.html, css/*.css, js/*.js' in bash and my project opens up. The project updates as expected when I change HTML, CSS, and/or JS files.
However, when I edit my package.json file (which is not in the same directory) under "scripts" with "start": browser-sync start --server --files '*.html, css/*.css, js/*.js' and then run npm start in my bash console I get a page but all I see is Cannot GET / and not my project.
Also, if I try to browser-sync start --server --files '*.html, css/*.css, js/*.js' or in any other project I get the same error.
If I do gulp browser-sync this is what I get:
[06:03:14] Working directory changed to ~\Google Drive
[06:03:15] Using gulpfile ~\Google Drive\gulpfile.js
[06:03:15] Starting 'browser-sync'...
[Browsersync] Access URLs:
--------------------------------------
Local: http://localhost:3000
External: http://192.168.1.116:3000
--------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.116:3001
--------------------------------------
[Browsersync] Serving files from: ./
Here is my gulpfile.js :
const gulp = require("gulp");
const browserSync = require('browser-sync').create();
gulp.task('browser-sync', function () {
browserSync.init({
server: {
baseDir: './',
}
});
});
And here is my package.json file:
{
"name": "eslint-test",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"browser-sync": "^2.24.6",
"gulp-sass": "^4.0.1"
},
"devDependencies": {
"eslint": "^4.18.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.9.0",
"gulp": "^4.0.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "browser-sync start --server --files '*.html, css/*.css, js/*.js'"
},
"author": "",
"license": "ISC"
}
I apologize if this is not the right place but I have searched and watched videos for about 2 hours with no answers found. I appreciate any and all help/links.

Categories

Resources