typia
typia copied to clipboard
Nx and typia setup docs
Hey @samchon,
I love typia and desperately want to integrate it with Nx (express app). I tried all I could find
- https://github.com/samchon/typia/issues/814
- https://github.com/samchon/nestia/issues/319
However, no matter what I do, I always get errors:
- 'rootDir' is expected to contain all source files.
- throw new Error(
Could not find ${fileToRun}. Make sure your build succeeded.
);
Since some people got it running, I would love to see the specific steps on how to set it up. Here is my current setup:
/apps/api/project.json
{
"name": "api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/api/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/api",
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"assets": ["apps/api/src/assets"],
"isolatedConfig": true,
"webpackConfig": "apps/api/webpack.config.js"
},
"configurations": {
"development": {},
"production": {}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "api:build"
},
"configurations": {
"development": {
"buildTarget": "api:build:development"
},
"production": {
"buildTarget": "api:build:production"
}
}
},
(I tried all kind of executors, specifically @nx/js:tsc and @nx/webpack:webpack)
apps/api/webpack.config.js
const path = require('path')
const nodeExternals = require('webpack-node-externals')
const { composePlugins, withNx } = require('@nx/webpack')
module.exports = composePlugins(withNx(), (config) => {
// Update the webpack config as needed here.
// e.g. `config.plugins.push(new MyPlugin())`
// CUSTOMIZE HERE
config.entry = ['./src/main.ts']
config.output = {
path: path.join(__dirname, 'dist'),
filename: 'main.js',
}
config.optimization = {
minimize: false,
}
// JUST KEEP THEM
config.mode = 'development'
config.target = 'node'
config.module = {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader',
},
],
}
config.resolve = {
extensions: ['.tsx', '.ts', '.js'],
}
return config
})
(basically merged nx default but also tried the provided webpack.config.js from the docs)
tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"moduleResolution": "node",
"strict": true,
"strictNullChecks": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"stripInternal": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"module": "commonjs",
"target": "ES2022",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"typeRoots": ["node_modules/@types"],
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@XXX/config": ["libs/config/src/main.ts"],
"@XXX/services": ["libs/services/src/index.ts"]
}
},
"ignorePatterns": [".eslintrc.cjs", "vite.config.ts"],
"transformers": ["typia/lib/transform"]
}
I'm looking forward to any answer! Best, René
With this option
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/api",
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"assets": ["apps/api/src/assets"],
"isolatedConfig": true,
"webpackConfig": "apps/api/webpack.config.js"
},
"configurations": {
"development": {},
"production": {}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "api:build"
},
"configurations": {
"development": {
"buildTarget": "api:build:development"
},
"production": {
"buildTarget": "api:build:production"
}
}
}
I can at least build it but I can not serve the app:
- throw new Error(`Could not find ${fileToRun}. Make sure your build succeeded.
- Error: write EPIPE
- node_modules/fork-ts-checker-webpack-plugin/lib/rpc/expose-rpc.js:5:58)
As I'm not using NX at all, have no insight about it.
If there's some NX user, then please help him.
@renesass Did you ever got this to work?
Unfortunately not :( I tried for too long and then give up switching to typebox. Maybe you have better luck?
Unfortunately not :( I tried for too long and then give up switching to typebox. Maybe you have better luck?
no I had to give up on NX too. I ended up using turborepo and it required no changes in the build setup, maybe you would be interested into that?
This way is not working? @loucass003 @renesass
https://nestia.io/docs/setup/#nx
@samchon Sadly no, according to https://github.com/samchon/nestia/issues/319#issuecomment-1828180666 it looks like the transformers are not compatible with Nx anymore
I tried myself for few hours and never got it to work 😭
I also tried to write a test code for type using packages managed by my company, but it failed. It seems to be an nx
problem.
Unfortunately, I also have no understanding of nx
.
I make the newest version nx (18.2.4) run with nestia in this example repo. See commit: https://github.com/honguyenhaituan/nx-typia/commit/c1df98cf949b84633448d9ec4edbcef3635a0927
I'm going to install it with this version and try it again. However, if the problem is reproduced every time the nx version is updated, I can consider removing it in the future. I will share the results later.