pm2 can't start typescript ESM - pm2

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 ?

Related

Eslint parsing Error: cannot read tsconfig.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

JetBrains WebStorm Jest encountered an unexpected token

I have a problem with running a simple project in WebStorm IDE. This is what I get when I hit run:
Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/home/patryk/WebstormProjects/Case Converter/node_modules/hs-test-web/hstest/stage/stageTest.js:12
runner = new PureJsApplicationRunner();
^
SyntaxError: Unexpected token =
at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (node_modules/hs-test-web/hstest/index.js:1:110)
At this moment, my project contains just 1 html file. I tried reinstalling nodejs and npm, but that didn't work
Good time of day,
I've encoutered the same problem with one Edu project in WebStorm IDE - when i pressed the "check" button for task - i've got issue:
"test suite failed to run
Jest encountered an unexpected token ..."
How it was solved:
Please check if nodejs and npm installed - At IDE: File\Settings, section: Languages & frameworks > nodejs and npm section > at field: "Node interpreter" you'll find something like : "node /usr/bin/node" and at field: "Package manager" the value "npm /usr/share/npm"
In IDE - you need to expand "Project pane" and to choose view mode "Project Files" - then you need open the file "package.json",
initially this file contains the code:
{
"devDependencies": {
"#types/jest": "^23.3.12",
"hs-test-web": "https://github.com/hyperskill/hs-test-web/archive/release.tar.gz",
"jest": "^27.3.1",
"puppeteer": ">=8.0.0"
},
"scripts": {
"test": "jest"
}
}
You need to add the section for "jest" - please found the complete package.json below
{
"devDependencies": {
"#types/jest": "^23.3.12",
"hs-test-web": "https://github.com/hyperskill/hs-test-web/archive/release.tar.gz",
"jest": "^27.3.1",
"puppeteer": ">=8.0.0"
},
"scripts": {
"test": "jest"
},
"jest": {
"verbose": true,
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"transformIgnorePatterns": ["/node_modules/(?!lodash-es)"],
"testRegex": "test/.*\\.spec\\.ts$"
}
}
So,i hope it help you.

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'
}

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.

Why "gulp-jest" is failing with: "Please run node with the --harmony flag!"?

I get the following error when running gulp test:
Error: Please run node with the --harmony flag!
Here is my gulp task:
var jest = require('gulp-jest');
gulp.task('test', function() {
return gulp.src('src/**/__tests__').pipe(jest({
rootDir: 'src',
scriptPreprocessor: '../node_modules/6to5-jest',
unmockedModulePathPatterns: [ 'react' ]
}));
});
To reproduce: https://github.com/SEEK-Jobs/react-playground
Note that npm test works properly (test is failing as expected), but gulp test fails with the error above. Both npm test and gulp test have the same config object:
{
rootDir: 'src',
scriptPreprocessor: '../node_modules/6to5-jest',
unmockedModulePathPatterns: [ 'react' ]
}
What am I doing wrong?
As far as I can tell the error is thrown from jest-cli.
The reason you don't get it with npm test is that you probably configured npm to run the jest bin script directly, which uses harmonize to programmatically set the --harmony flag.
You can fix by installing harmonize and putting require('harmonize')() in your gulpfile.
It was a bug in gulp-eslint, and it is fixed now in version 0.3.0.