Ncc: Typescript with `paths` option breaks every deploy

Created on 22 Feb 2019  路  6Comments  路  Source: vercel/ncc

If I add typescript paths to tsconfig and try to import using them, any example from now-examples breaks the deploy.

Example repo:

https://github.com/pie6k/zeit-now-typescript-broken-example

Reproduction

  1. run now
  2. make request

Actual result

502: An error occurred with your deployment
Code: NO_STATUS_CODE_FROM_LAMBDA (more)

(logs) - https://nodejs-koa-ts-k14ww3xqd.now.sh/_logs

Unable to import module 'launcher': Error
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.285 (/var/task/user/src/routes/default.ts:3499:18)
    at __webpack_require__ (/var/task/user/src/routes/default.ts:22:30)
    at Module.736 (/var/task/user/src/routes/default.ts:10958:21)
    at __webpack_require__ (/var/task/user/src/routes/default.ts:22:30)
    at startup (/var/task/user/src/routes/default.ts:36:19)
    at /var/task/user/src/routes/default.ts:42:18

I've tried with working examples from now-examples

As soon as I've added paths to eg. koa example - it was broken in the same way -

Koa example:

https://github.com/pie6k/zeit-now-typescript-broken-example/tree/7bd024e3aaf61b7e0cc8f71412e29eed85deab7e/nodejs-koa-ts - example repo (folder nodejs-koa-ts ->> default.ts route) - same steps for reproduction.

bug

All 6 comments

@pie6k tsconfig.json paths are only supported for the TypeScript checker, and don't become used as include paths in ncc itself. Marking as an enhancement.

https://github.com/zeit/ncc/blob/master/src/index.js#L63 - it seems like you're using it already, but it's not working

@pie6k you're right, the implementation in https://github.com/zeit/ncc/pull/151 does intend this to work it seems, so it is a bug.

Hmm, looking at this again, if I run:

git clone [email protected]:pie6k/zeit-now-typescript-broken-example
cd zeit-now-typescript-broken-example/api
yarn install
ncc run index.ts

execution does complete fine for me with this.

Can you share an exact ncc replication of the bug? Otherwise, perhaps this isn't an ncc bug?

Running build with ncc seems to work, but deploying it to now results in broken deploy:

Unable to import module 'launcher': Error
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.285 (/var/task/user/src/routes/default.ts:3499:18)
    at __webpack_require__ (/var/task/user/src/routes/default.ts:22:30)
    at Module.736 (/var/task/user/src/routes/default.ts:10958:21)
    at __webpack_require__ (/var/task/user/src/routes/default.ts:22:30)
    at startup (/var/task/user/src/routes/default.ts:36:19)
    at /var/task/user/src/routes/default.ts:42:18

You can replicate it by

git clone git clone [email protected]:pie6k/zeit-now-typescript-broken-example
cd zeit-now-typescript-broken-example
now

and then go to generated url.

As soon as custom path import is removed from the code - it works.

Error says it cannot load this file: https://github.com/zeit/now-builders/blob/master/packages/now-node/src/launcher.ts

It is loaded something like (https://github.com/zeit/now-builders/blob/master/packages/now-node/src/index.ts#L104)

const launcherPath = join(__dirname, 'launcher.js');
  let launcherData = await readFile(launcherPath, 'utf8');

Which suggests that maybe injecting ts-paths plugin to node resolution might break this custom loading of file here. Just guessing. But that could be reason why building it with ncc works while running it fails to load some custom files.

https://www.npmjs.com/package/tsconfig-paths - here is docs of tsconfig-paths plugin and it says it's modify node resolution. Maybe there is some conflict here.

hard to tell for me where is the root cause of this.

I'm closing because this does not appear to be a bug with ncc.

I followed the steps to reproduce and it works fine locally.

Let's continue this discussion in the now-builders repo here: https://github.com/zeit/now-builders/issues/233

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomakado picture tomakado  路  4Comments

rgbkrk picture rgbkrk  路  3Comments

drewolson picture drewolson  路  3Comments

rauchg picture rauchg  路  3Comments

guybedford picture guybedford  路  5Comments