Typescript prod deployment

You might want to try upgrading soon, especially if you’re using Auth package as Peter’s been continually making improvements. However, I don’t believe this will fix the build issue, unfortunately. :confused:

1 Like

I’ve fixed this over here: https://github.com/redwoodjs/redwood/pull/703

1 Like

Hello guys!
Many thanks for the messages :slightly_smiling_face:
I missed it, I saw the extensions specified in a build command I mistook for the one @peterp fixed.
I’m eager to test it, unfortunately my laptop is sitting on the doctor’s bench for a couple of days. I’ll try it out as soon as I get it back :slightly_smiling_face: and keep you updated!
Thanks again \o/

1 Like

@peterp I’ve ran the command both locally and on netlify, the issue doesn’t seem to be sorted.
Here’s my tree for services:

api/src/services
├── authors
│   └── authors.js
├── books
│   ├── books.ts
│   └── strategy
│       ├── exceptions.js
│       ├── google.js
│       └── nodeisbn.ts
├── categories
│   └── categories.js
├── collections
│   └── collections.js
├── labels
│   ├── labels.test.js
│   └── labels.ts
├── localisations
│   └── localisations.js
├── ownerships
│   └── ownerships.ts
├── publishers
│   └── publishers.js
├── tokens
│   └── tokens.js
└── users
    └── users.ts

The .js is handled properly but the .ts is still completely ignored, locally and on netlify.
I have pulled the last version of redwoodjs including your branch that fixes the deploy of .ts files and confirmed that it was the proper package.json that was used with the updated command.

I have also tried it on the invoice-example and can confirm it does not work either. Have you had success with it?

Seeing the same issue as @noire.munich - tried patch-package with your changes, but no luck. This is the error log for reference:

2:41:49 PM:   Error message
2:41:49 PM:   Error: In file "/opt/build/repo/api/dist/functions/graphql.js": Cannot find module '../lib/auth' from '/opt/build/repo/api/dist/functions'
2:41:49 PM: ​
2:41:49 PM:   Plugin details
2:41:49 PM:   Package:        @netlify/plugin-functions-core
2:41:49 PM:   Version:        2.0.10
2:41:49 PM:   Repository:     git+https://github.com/netlify/build.git
2:41:49 PM:   npm link:       https://www.npmjs.com/package/@netlify/build
2:41:49 PM:   Report issues:  https://github.com/netlify/build/issues
2:41:49 PM: ​
2:41:49 PM:   Error location
2:41:49 PM:   In "onPostBuild" event in "@netlify/plugin-functions-core" from core
2:41:49 PM:       at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:142:35
2:41:49 PM:       at load (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:161:43)
2:41:49 PM:       at onex (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:186:17)
2:41:49 PM:       at /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/resolve/lib/async.js:13:69
2:41:49 PM:       at FSReqCallback.oncomplete (fs.js:167:21)
2:41:49 PM: ​
2:41:49 PM:   Error properties
2:41:49 PM:   { code: 'MODULE_NOT_FOUND' }

It looks like a post-build issue, when netlify is trying to deploy functions.

Update: just verified its not producing the files locally either

Hi all, just checking in here – any updates on progress or fixes here?

Thanks for being TS trailblazers! But we understand the pain of trailblazing can be no fun.

1 Like

I did the thing where I thought I fixed it, but didn’t test it. I’ve now actually fixed it and tested it in this PR: https://github.com/redwoodjs/redwood/pull/744

Hi @thedavid and @peterp - thanks for checking in and the fix.

Unfortunately this looks like a partial fix, it now generates the js files but the imports in the generated graphql.js looks incorrect. The build still fails trying to import services in ts. In my case its github.ts

Netlify build log snippet

12:33:21 PM:   Error message
12:33:21 PM:   Error: In file "/opt/build/repo/api/dist/functions/graphql.js": Cannot find module './../services/github/github.ts' from '/opt/build/repo/api/dist/functions'

Snippet from generated graphql.js

.
.
var _servicesGithubGithubTs = _interopRequireWildcard(require("./../services/github/github.ts"));

var _servicesGithubTypesTs = _interopRequireWildcard(require("./../services/github/types.ts"));
.
.

Its probably the importAll.macro that doesn’t know how to handle ts. I tried modifying it a bit - but it looks like its depracated anyway. Maybe I should import services differently? An example would be really helpful (without needing to import each service by hand ideally!)

Indeed! **shakes fist at importAll.macro**

Could you try: import services from 'src/services/*.{js,ts}' instead?

At the moment, we do not support nested directories in services.

Yep tried that, but services end up an empty array (in the compiled code)!

Ok, I’m going to have to modify this to support sub-directories in the services folder.

Before you do, hold on I think the reason its failing is because it tries to import the tests also. Removed all the service tests (!!!) and it seems to work in dev. Waiting for netlify build now :slight_smile:

I’m using this to get through subdirectories:

import services from 'src/services/*/*.{js,ts}'
1 Like

Well unfortunately, the result is the same, its trying to import ts files in the compiled graphql.js.

On the plus side, I learnt about * imports - I had no idea you could do wildcard imports!

This is something that we’ve written ourselves!

Fixes for nested subdirectories might take a bit longer, but I can very quickly solve the issue with the file extension (we can plop them off the generated asts, since nodejs knows how to resolve them!)

If anyone is keen to try a PR you should modify this line to pop off the extension: https://github.com/redwoodjs/redwood/blob/0dc1afe90bec6276e6ac363f759f0cb673bac7dc/packages/core/src/babel-plugin-redwood-import-dir.ts#L60

And when you run the tests:

cd packages/core
yarn test:watch

The result should be that this output file should no longer contain extensions:
https://github.com/redwoodjs/redwood/blob/0dc1afe90bec6276e6ac363f759f0cb673bac7dc/packages/core/src/tests/fixtures/import-dir/import-dir-default/output.js#L1-L7

No rush though, I’ll make sure to do this before the end of the day.

Oh man, :man_facepalming:, we should make our build script ignore .test.* files.

Here you are @peterp :slight_smile:

Also implemented ignore test files

1 Like

Hi All! Wanted to let you know v0.12.0 has shipped and includes fixed for TS deploy. Please let us know how it goes when you have a chance to try it out.

Hello people :slight_smile:

So I’ve tried - and failed again at deploying.
However there’s some progress.

My .ts files now seem to be properly transpiled to .js and I can now find them in the dist directory.
But as it happens api/dist/functions/graphql.js in its _interopRequireWildcard imports writes, unexpectedly enough, extensions as .ts - hence the bump on deploy: the files are here, properly turned to .js, but the generated graphql.js still calls the original extensions.

I’d like to look into it and see how we could force writing .js, because, and please correct me on this dear community, we will expect exclusively .js files in our /dist… right?

In any case, THANKS a heartfelt lot to everyone who’s working on the TS matter :), I’m converting my entire app thanks to this.

Right now we automatically use the importAll.macro, but I’ve written a different version that allows you specify the syntax like this:

import services from 'src/services/*/*.{js,ts}'

And that should be working in v0.12.0 - the only caveat is that it will not support nested directories, but that will be coming before the end of the week and then we’ll deprecate importAll.macro

1 Like