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

Typescript with paths option breaks every deploy #291

Closed
pie6k opened this issue Feb 22, 2019 · 6 comments
Closed

Typescript with paths option breaks every deploy #291

pie6k opened this issue Feb 22, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@pie6k
Copy link

pie6k commented Feb 22, 2019

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.

@pie6k pie6k changed the title Typescript with paths breaks deploy Typescript with paths breaks deploy - Unable to import module 'launcher' Feb 22, 2019
@pie6k pie6k changed the title Typescript with paths breaks deploy - Unable to import module 'launcher' Typescript with paths option breaks every deploy Feb 25, 2019
@guybedford
Copy link
Contributor

@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.

@guybedford guybedford added the enhancement New feature or request label Feb 25, 2019
@pie6k
Copy link
Author

pie6k commented Feb 25, 2019

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

@guybedford
Copy link
Contributor

@pie6k you're right, the implementation in #151 does intend this to work it seems, so it is a bug.

@guybedford guybedford added bug Something isn't working and removed enhancement New feature or request labels Feb 25, 2019
@guybedford
Copy link
Contributor

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?

@pie6k
Copy link
Author

pie6k commented Feb 25, 2019

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.

@styfle
Copy link
Member

styfle commented Mar 25, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants