Error: ESLint configuration in --config is invalid - json

I am facing the error while using the command npm run start:
Error: ESLint configuration in --config is invalid:- Unexpected top-level property "compilerOptions".
I cannot figure out the cause of the error. I tried adding root:true and many other solutions that i stumbled upon.
My package.json File :
{
"name": "discord-bot",
"version": "1.0.0",
"description": "",
"main": "dist/WebServer.js",
"scripts": {
"prebuild": "eslint . --ext .js,.jsx,.ts,.tsx -c tsconfig.json --fix",
"lint": "eslint . --ext .ts,.tsx",
"lint-and-fix": "eslint . --ext .ts,.tsx --fix",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Anup",
"license": "ISC",
"dependencies": {
"express": "^4.17.2"
},
"devDependencies": {
"#types/express": "^4.17.13",
"#types/node": "^17.0.9",
"#typescript-eslint/eslint-plugin": "^5.10.0",
"#typescript-eslint/parser": "^5.10.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"typescript": "^4.5.4"
}
}
My eslintric.js file :
module.exports = {
root: true,
parser: "#typescript-eslint/parser",
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
},
plugins: ["#typescript-eslint"],
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
extends: [
"eslint:recommended",
"plugin:#typescript-eslint/recommended",
"plugin:#typescript-eslint/recommended-requiring-type-checking",
"prettier",
],
};
My tsconfig.json File :
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
}
},
"include": ["Web/*"]
}
When I run the npm run start without the prebuild in the script my application works.

Related

Firebase Cloud Functions TypeScript error: Unknown file extension ".ts" for /workspace/src/index.ts

When I run firebase deploy --only functions I get this error:
Build failed: node:internal/errors:477
ErrorCaptureStackTrace(err);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /workspace/src/index.ts
at new NodeError (node:internal/errors:387:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:76:11)
at defaultGetFormat (node:internal/modules/esm/get_format:118:38)
at checkSyntax (node:internal/main/check_syntax:57:26) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}; Error ID: 037e0eb0
Functions deploy had errors with the following functions:
triggerMe(us-central1)
I'm also getting an error in the Firebase Console showing a red triangle next to this function, saying Function deployment failed. Please try again.
I ran npm outdated and npm update, everything is the latest version.
Here's my index.ts file:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.triggerMe = functions.firestore.document('Triggers/{docId}').onWrite((data, context) => {
console.log("Trigger warning!")
console.log(data.message);
return 30
});
I was getting errors about the data and context parameters being implicit any type so I added "noImplicitAny": false, to tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"noImplicitAny": false,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
I also tried switching strict to false. This didn't help.
In my environments.ts file I added useEmulators: true. I get this error whether this property is set to true or false.
Here's my functions/package.json:
{
"name": "functions",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "src/index.ts",
"dependencies": {
"firebase-admin": "^10.2.0",
"firebase-functions": "^3.21.0"
},
"devDependencies": {
"typescript": "^4.8.4"
},
"private": true
}
And the other package.json file:
{
"name": "triggerable-functions-tutorial",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"#angular/animations": "^14.2.0",
"#angular/common": "^14.2.0",
"#angular/compiler": "^14.2.0",
"#angular/core": "^14.2.0",
"#angular/fire": "^7.4.1",
"#angular/forms": "^14.2.0",
"#angular/platform-browser": "^14.2.0",
"#angular/platform-browser-dynamic": "^14.2.0",
"#angular/router": "^14.2.0",
"firebase": "^9.12.1",
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.1",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "^14.2.6",
"#angular/cli": "~14.2.6",
"#angular/compiler-cli": "^14.2.0",
"#types/jasmine": "~4.3.0",
"jasmine-core": "~4.4.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.8.4"
}
}
And firebase.json:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
}
Try the following solution:
Remove the "type": "module" from the package.json if added, it looks like you don't have it.
In tsconfig.json, under the compilerOptions, set the "moduleResolution": "Node".
Like so:
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node"
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"noImplicitAny": false,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
Source: Can't run my Node.js Typescript project TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/App.ts
I added "type": "module", to package.json. This got rid of the ERR_UNKNOWN_FILE_EXTENSION error. I also upgraded the dependencies to the latest versions.
{
"name": "functions",
"type": "module",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "src/index.ts",
"dependencies": {
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.1"
},
"devDependencies": {
"typescript": "^4.8.4"
},
"private": true
}
I now get this error:
Function failed on loading user code. This is likely due to a bug in the user code.
I changed (data, context) to (data: any, context: any) and that error was replaced with this error:
SyntaxError: Unexpected token ':'
I have "noImplicitAny": false, in tsconfig.json. Changing that to true throws the expected error (indicating that the property is working):
Parameter 'data' implicitly has an 'any' type.
I removed noImplicitAny and set strict to false. This threw this error:
Function failed on loading user code. This is likely due to a bug in the user code.
I'm giving up and using JavaScript.

ionic fails to load html and css of a component in an npm package

I am trying to create a npm package that will have a angular2 dummy component i.e. a .ts file which references its .css file and .html file.
When I install this package in an angular project, it works fine referencing the relative paths of html and css files.
However the same fails to load html and css files in an IONIC2 project.
I believed ionic2 is made using angular2 and this should have worked.
My tsconfig.json looks like -
{
"compilerOptions": {
"baseUrl": "",
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2015",
"dom"
],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "../dist",
"declarationDir": "../dist",
"declaration": true
},
"compileOnSave": true,
"exclude": [
"node_modules",
"dist"
] }
and package.json -
{
"name": "componentlibrarytest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"prestart": "npm run build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"test components"
],
"private": true,
"devDependencies": {
"#angular/common": "^2.4.0",
"#angular/compiler": "^2.4.0",
"#angular/core": "^2.4.0",
"#angular/forms": "^2.4.0",
"#angular/http": "^2.4.0",
"#angular/platform-browser": "^2.4.0",
"#angular/platform-browser-dynamic": "^2.4.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.7.6",
"typescript": "~2.3.2"
},
"author": "XYZ",
"license": "ISC"
}
I guess I am missing something to bundle up html and css files. Do i need to use webpack or something?

Angular-cli SyntaxError: Unexpected token ]

I just pulled the new version of my project with git and angular-cli stopped working. When I start it, I get the following error:
Parsing .angular-cli.json failed. Please make sure your .angular-cli.json is valid JSON. Error:
SyntaxError: Unexpected token ] in JSON at position 1044
InvalidConfigError: Parsing .angular-cli.json failed. Please make sure your .angular-cli.json is valid JSON. Error:
SyntaxError: Unexpected token ] in JSON at position 1044
My angular-cli.json file is the following:
{
"project": {
"version": "1.0.0-beta.22-1",
"name": "quest"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.less",
"../node_modules/angular2-toaster/toaster.css",
"../node_modules/bootstrap-slider/dist/css/bootstrap-slider.min.css",
"../node_modules/bootstrap-timepicker/css/bootstrap-timepicker.css",
"../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/bootstrap/dist/js/bootstrap.js",
"../node_modules/admin-lte/dist/js/app.js",
"../node_modules/bootstrap-slider/dist/bootstrap-slider.js",
"../node_modules/bootstrap-timepicker/js/bootstrap-timepicker.min.js",
"../node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
I tried updating angular-cli, I tried deleting node_modules et running npm install. I have node version 6.9.5. I tried parsing the angular-cli.json with some JSON validation tools.
Any other idea?

npm install that loads dependency with package.json as authored

I noticed that when viewing a package.json under node_modules, I see JSON that looks like:
{
"_args": [
[
"example#0.2.0",
"C:\\path\\to\\project\\folder"
]
],
"_from": "example#0.2.0",
"_id": "example#0.2.0",
"_inCache": true,
"_installable": true,
"_location": "/example",
"_nodeVersion": "6.2.0",
"_npmUser": {},
"_npmVersion": "3.8.9",
"_phantomChildren": {},
"_requested": {
"name": "example",
"raw": "example#0.2.0",
"rawSpec": "0.2.0",
"scope": "#edf",
"spec": "0.2.0",
"type": "version"
},
"_requiredBy": [
"/"
],
"_resolved": "http://internal.registry/example/-/example-0.2.0.tgz",
"_shasum": "b564b263db925ff3a8bffdc922c16f8e4b6f4641",
"_shrinkwrap": null,
"_spec": "example#0.2.0",
"_where": "C:\\path\\to\\project\\folder",
"author": {
"name": "NPM User"
},
"dependencies": {
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-less": "^3.1.0"
},
"description": "Example Package",
"devDependencies": {},
"dist": {
"shasum": "b564b263db925ff3a8bffdc922c16f8e4b6f4641",
"tarball": "http://internal.registry/example/-/example-0.2.0.tgz"
},
"main": "index.js",
"name": "example",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"readmeFilename": "README.md",
"scripts": {
"postinstall": "gulp"
},
"version": "0.2.0"
}
Instead of just:
{
"name": "example",
"version": "0.2.0",
"description": "Example Package",
"main": "index.js",
"scripts": {
"postinstall": "gulp"
},
"author": "NPM User",
"dependencies": {
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-less": "^3.1.0"
}
}
Is there a command-line argument I can specify to keep dependency package.json files as authored when installing, or is there another way I can access the file as authored when there is no repository specified for the package?
I found an option called proprietary-attribs on the npm-config documentation but I don't think that's what I'm looking for.

Gulp-notify compile error

I am using gulpfile.js but it is throwing compile time error for gulp-notify
Following is structure of package.json
{
"name": "flux-pricing",
"version": "0.0.1",
"description": "Pricing component with flux",
"main": "gulpfile.js",
"dependencies": {
"flux": "^2.0.0",
"react": "^0.12.0",
"underscore": "^1.7.0"
},
"devDependencies": {
"envify": "~1.2.1",
"browserify": "~4.2.0",
"gulp": "~3.9.0",
"gulp-notify": "~1.4.0",
"gulp-util": "~2.2.19",
"reactify": "~0.13.1",
"vinyl-source-stream": "~0.1.1",
"watchify": "~0.10.2"
},
"scripts": {
"start": "watchify -o js/bundle.js -v -d .",
"build": "browserify . | uglifyjs -cm > js/bundle.min.js"
},
"author": "Ken Wheeler",
"browserify": {
"transform": [
"reactify",
"envify"
]
}
}