Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nx and typia setup docs #900

Open
renesass opened this issue Dec 8, 2023 · 10 comments
Open

Nx and typia setup docs #900

renesass opened this issue Dec 8, 2023 · 10 comments
Labels
help wanted Extra attention is needed

Comments

@renesass
Copy link

renesass commented Dec 8, 2023

Hey @samchon,

I love typia and desperately want to integrate it with Nx (express app).
I tried all I could find

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é

@renesass
Copy link
Author

renesass commented Dec 8, 2023

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)

@samchon
Copy link
Owner

samchon commented Dec 19, 2023

As I'm not using NX at all, have no insight about it.

If there's some NX user, then please help him.

@samchon samchon added the help wanted Extra attention is needed label Dec 19, 2023
@loucass003
Copy link

@renesass Did you ever got this to work?

@renesass
Copy link
Author

Unfortunately not :( I tried for too long and then give up switching to typebox. Maybe you have better luck?

@loucass003
Copy link

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?

@samchon
Copy link
Owner

samchon commented Jan 22, 2024

This way is not working? @loucass003 @renesass

https://nestia.io/docs/setup/#nx

@loucass003
Copy link

loucass003 commented Jan 22, 2024

@samchon Sadly no, according to samchon/nestia#319 (comment)
it looks like the transformers are not compatible with Nx anymore

I tried myself for few hours and never got it to work 😭

@kakasoo
Copy link
Sponsor Contributor

kakasoo commented Apr 11, 2024

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.

@honguyenhaituan
Copy link

I make the newest version nx (18.2.4) run with nestia in this example repo. See commit: honguyenhaituan/nx-typia@c1df98c

@kakasoo
Copy link
Sponsor Contributor

kakasoo commented Apr 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants