ncc icon indicating copy to clipboard operation
ncc copied to clipboard

publishing the output of ncc as npx package doesn't work

Open CatsAndDogs123 opened this issue 3 years ago • 1 comments

Hello,

I wanted to test ncc for npx package, this is the project - https://github.com/CatsAndDogs123/try-ncc I used the example from https://github.com/vercel/ncc/tree/main/examples/multiple-bundles And changed the package.json a bit to be like the one in create-next-app: https://github.com/vercel/next.js/blob/canary/packages/create-next-app/package.json

Now when i published the package and ran the command npx try-ncc I got the following error:

The input line is too long.
The syntax of the command is incorrect.

So i wanted to see the output of the package - so I npm installed it and I found out that the node_modules/.bin/try-ncc.cmd file looks like this:

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
@SET n=t(707);r.color

IF EXIST "%dp0%\color(){const.exe" (
  SET "_prog=%dp0%\color(){const.exe"
) ELSE (
  SET "_prog=color(){const"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" color=Math.random()>.5?"red":"blue";return`Your lucky color is ${n[color](color)}`};r.number=function number(e=0,r=100){e=Math.ceil(e);r=Math.floor(r);const t=Math.floor(Math.random()*(r-e))+e;return`Y

The full complied code was there (I didnt put here everything its too long).

Then, I wanted to see how the file node_modules/.bin/create-next-app.cmd in create-next-app looked like, so i npm installed it, and it looks like this:

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%"  "%dp0%\..\create-next-app\dist\index.js" %*

which is good - it has a reference to the output code and not have there all the compiled code. And thats the reason why I got the errors I got.

Now, I don't understand why for me it didn't work, I did exactly the same.

Moreover, I copied the create-next-app project and tried it and again i get the same errors and I checked and saw again the full compiled code in the .cmd file.

I'm not sure whats happening here, any help is appreciated.

Edit:

It seems like the problem is solved when i placed an empty line between: #!/usr/bin/env node and the rest of compiled code or running prettier on the file.

Both fixed the problem and the .cmd file looks good now, my guess is that the #!/usr/bin/env node is getting mixed with the rest of compiled code and it counts as one thing.

Not sure if this is a problem or not, if not the issue can be closed.

CatsAndDogs123 avatar Jan 10 '22 00:01 CatsAndDogs123

I am seeing the exact same behaviour. It seems the newline is required for node to correctly generate the cmd file

bobvandevijver avatar Mar 24 '23 19:03 bobvandevijver