Eslint parsing Error: cannot read tsconfig.json - json

i have such structure of my dirs:
-projects
--MyProject
---MyDir
tsconfig.json
eslinttrc.json
in my eslinttrc.json i have
"parserOptions": {
"ecmaVersion": "latest",
"project": ["tsconfig.json"],
"sourceType": "module"
}
and also in this dir i have tsconfig.json but eslint gives me an error
"cannot read project\tsconfig.json" - and that because lint is starting search from wrong root dir "projects" not from "MyDir"
And if i point in parseOption path like "*/MyDir/tsconfig.json" - eslint will find right way
How to fix my parseOption project path to from '/MyDir/tsconfig.json' to ./tsconfig.json'

You have probably found an answer already, but if this appears again adding
project: path.join(__dirname, "tsconfig.eslint.json")
to your .eslintrc.js file helps. Have a look at this Github thread for reference

Related

pm2 can't start typescript ESM

I want to start typescript ESM in pm2
I configure ESM module:
add "type": "module" to package.json
add "module": "Node16" to tsconfig.json
add "esm": true to ts-node section of tsconfig.json
I try to start a simple program main.ts using pm2:
import { msg } from './lib/helper.js';
msg('Hello world!');
and received this error:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /var/node/srv2/src/main.ts
standard command work ok: ts-node src/main.ts
I try to use ecosystem.config.cjs - but it's not work too.
I put full example to github:
https://github.com/gayratv/pm2-typesript-esm
Is any way to start typescript ESM using pm2 ?

VSCode typescript importing json file highlighting issue

I have some strange behaviour when importing json files using the import statement in typescript while using VSCode. Note this is not an issue with typescript itself just VSCode highlighting.
I have edited my tsconfig.json adding resolveJsonModule and esModuleInterop with the value of true to my compiler options to enable importing json within typescript.
Also I have added this package to my project
https://www.npmjs.com/package/json-d-ts
and added a typeRoots attribute to the tsconfig.json with a value of ["node_modules/json-d-ts"]
I've imported the json file (found at src/config/firebaseServiceKey.json) within a module (found at src/firebaseApp.ts) which is within a parent directory, thus the import looks like this:
import databaseUrl from "./config/firebaseDatabaseURL.json";
VSCode does not complain about this import:
However I have another module which imports the same file at a different level in the project directory, this module is found at test/utils.ts its import look like this:
import serviceKey from "../src/config/firebaseServiceKey.json";
This time VSCode does not seem to like the relative import and highlights the module as missing:
Any ideas how to fix configure VSCode to fix this problem?
Here is the relevant section of the result of running tsc --traceResolution:
======== Resolving module '../src/config/firebaseServiceKey.json' from '/home/jty/April2018/vs-server/test/utils.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
Loading module as file / folder, candidate module location '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json', target file type 'TypeScript'.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.ts' does not exist.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.tsx' does not exist.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.d.ts' does not exist.
Directory '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json' does not exist, skipping all lookups in it.
Loading module as file / folder, candidate module location '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json', target file type 'JavaScript'.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.js' does not exist.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.jsx' does not exist.
Directory '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json' does not exist, skipping all lookups in it.
Loading module as file / folder, candidate module location '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json', target file type 'Json'.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json' exist - use it as a name resolution result.
======== Module name '../src/config/firebaseServiceKey.json' was successfully resolved to '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json'. ========
Here is my tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
}
},
"include": [
"src/**/*"
],
"typeRoots": [
"node_modules/json-d-ts"
]
}
I have faced similar issue, check your file is included as #Matt McCutchen said, the file which contains
import serviceKey from "../src/config/firebaseServiceKey.json";
should be included under src folder as you described in the tsconfig.json
"include": [
"src/**/*"
],
In my case, it was a test file which should not be included in the build. Because of that I have decided to ignore that highlight in the vs.
// #ts-ignore
import packageJson from '../../../../package.json';

How to prevent optimization of text! and json! plugins on r.JS tool from Require.JS?

Already seen many topics here but none of the pointed solutions worked.
When optimizing my project, R.js is failing to handle this json! plugin dependency on one of my modules.
Error message:
Tracing dependencies for: app/productApp
TypeError: errback is not a function
In module tree:
app/productApp
blah
json
My r.js build config file:
define([
'productApp',
'json!blah'
], function(...){...}
and here is my r.js config file:
({
name: 'app/productApp',
out: '../app.js',
optimize: 'uglify2',
findNestedDependencies: true,
inlineJSON: false,
inlineText: false,
exclude: [ 'json!blah' ]
)}
I've already tried all possible ways, such as an exclude on the r.js config file, or and adding '!bust' at the end of the dependency list, but no luck.
Require.js / R.js version: 2.2.0
One detail: I'm running r.js through node package.json script, triggered by maven.
Thoughts?
Found the solution. It turns out that the paths to the json and text libraries were missing from require config file. (it can't be just made 'empty:' within r.js build config file).
This then would fix the issue:
...
paths: {
'text': 'lib/text',
'json': 'lib/json',
...
},
exclude: {
'json!blah'
}

Webpack dev server configuration refuse to work with full path to index

Hello I am trying to understand why does webpack dev server refuse to work with full path to my index.js. (I am using webpack with babel to build reactJS.)
At the moment my webpack.config is located in the same directory as my index.js file and due to that the declaration of the entry point of my index.js is just "./index". Here is how my webpack.config looks like:
module.exports = {
devtool: 'inline-source-map',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.js']
},
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
include: __dirname
}]
}};
With this configuration my project is build by babel and works just fine on the server!
My problem comes when I tried to specify a full path of my index.js entry point. I need that because I want to externalize the webpack and it's configuration from my FE code. To be sure that it will work I first tried not to rely that webpack.config and index.js are in the same directory but to specify the path of the index as full path name:
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'D:/projects/myProject/index'
]
With this config babel seem to be able to navigate to the index.js and start compiling it, but it does encounter an unexpected (for me) error during the parse:
ERROR in D:/projects/myProject/index.js
Module parse failed: D:/projects/myProject/index.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import 'babel-core/polyfill';
|
| import React from 'react';
# multi main
What do I miss, why webpack makes difference between relatively configured index.js and full path one?
(I made sure that the full path is correct)
Thanks!
After a bit annoying investigation it appeared that my problem is specifying the Windows drives in uppercase. For some reason it appear that the index.js location full path should start with lowercase drive letter!
Hopefully this experience may be helpful to others.
Try using:
d:/Folder1/folder2/index.js
instead of
D:/Folder1/folder2/index.js

Why does main-bower-files filter some packages?

I've got a gulp task which is intended to copy bower dependencies to another folder, but only a subset of the dependencies are being matched.
Here's a simplified version of the task which just prints out the matching paths:
gulp.task('list-dependencies',function() {
gulp.src(mainBowerFiles('**/*'), { base: './bower_components' })
.pipe($.print());
});
Here's the bower.json file contents:
bower.json
{
"name": "app",
"private": true,
"dependencies": {
"bootstrap": "3.0.0",
"jquery": "1.10.2",
"modernizr": "~2.8.3",
"angular": "~1.4.4",
"angular-ui": "~0.4.0",
"angular-route": "~1.4.4"
}
}
Here's a listing of the bower_components folder:
$ ls bower_components/
angular angular-route angular-ui bootstrap jquery modernizr
outut:
[13:30:08] Starting 'list-dependencies'...
[13:30:08] Finished 'list-dependencies' after 27 ms
[gulp] bower_components\jquery\jquery.js
[gulp] bower_components\angular\angular.js
[gulp] bower_components\angular-route\angular-route.js
[gulp] bower_components\bootstrap\dist\js\bootstrap.js
[gulp] bower_components\bootstrap\dist\css\bootstrap.css
As you can see, angular-ui and modernizr aren't listed. Can someone explain why this is happening?
Bower has a concept of defining "main" files within a bower.json. The packages that were missed were due to the fact that these packages didn't contain a bower.json file which defined the main files. To get the main-bower-files plugin to work, you have to define overrides either within your bower file or as a parameter to main-bower-files.