I really like the structure of a NX workspace, and that lead me to start using it when building a new CLI project.
I started with creating a @nrwl/node:application but i currently is having some issues making it executable.
I believe this is not a problem with NX itself, but i can't add a shebang #!/usr/bin/env node in the main.ts file since the tsc transpiler will complain.
Module parse failed: Unexpected character '#' (1:0) File was processed
with these loaders: * ./node_modules/ts-loader/index.js
I have added the "bin": {"cli": "main.js"} property in my package.json file but if i run the main.js file without the shebang i will get this error:
line 1: syntax error near unexpected token `('
C:\Users\*\AppData\Roaming\npm/node_modules/*/dist/apps/*/main.js: line 1: `(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
Is there any smart way of solving this?
Steps to reproduce:
npx create-nx-workspace@latest cli-workspace --preset empty --cli nx --nx-cloud falsecd cli-workspacenpm install -D @nrwl/nodenx generate @nrwl/node:application my-cli- Add
#!/usr/bin/env nodeto the top of the main.ts file npm start