tommedema / serverless-mono-example

Example repo on how to use yarn workspaces together with the serverless framework.
124 stars 10 forks source link

Failed running yarn build from root #3

Closed justinwaite closed 6 years ago

justinwaite commented 6 years ago

First off, just want to say this is a great starter project, and perfect timing! It seems every time I start researching a new stack/paradigm someone just released something 4 days prior!

Just a quick issue while testing out the repo: when I run yarn build from the root dir per the README documentation, I receive the following Typescript errors:

yarn run v1.9.2
$ tsc -b .
node_modules/@types/node/index.d.ts:34:22 - error TS6305: Output file '/Users/justin/WebstormProjects/serverless-mono-example/packages/typesnode_modules/@types/node/inspector.d.ts' has not been built from source file '/Users/justin/WebstormProjects/serverless-mono-example/node_modules/@types/node/inspector.d.ts'.

34 /// <reference path="./inspector.d.ts" />
                        ~~~~~~~~~~~~~~~~

packages/sls-random/src/index.ts:6:8 - error TS2307: Cannot find module 'aws-lambda'.

6 } from 'aws-lambda'
         ~~~~~~~~~~~~

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

However, building from within the individual packages appears to work just fine.

tommedema commented 6 years ago

Thanks!

I added aws-lambda as a dev dependency under sls-random because it's only there for type checking. Did you run yarn install prior to yarn build? Without the --production flag?

justinwaite commented 6 years ago

Of course! I smashed my face against a wall trying to get something like this going before I found your repo!

As for the steps I took -- simply clone the repo, cd into it, run yarn install and then run yarn build and I receive those errors.

Looking into this further, the error occurs because of the sls-random package, as you said, depends on aws-lambda. I believe the nohoist option causes the aws-lambda package to not get installed on the root node_modules, although it IS installed on the sls-random node_modules. Maybe that is the cause? For some reason it is not looking in the child node_modules folders when building in the root? Not sure...

As for the first error:

node_modules/@types/node/index.d.ts:34:22 - error TS6305: Output file '/Users/justin/WebstormProjects/trashme/packages/typesnode_modules/@types/node/inspector.d.ts' has not been built from source file '/Users/justin/WebstormProjects/trashme/node_modules/@types/node/inspector.d.ts'.

34 /// <reference path="./inspector.d.ts" />

Any idea what that would be?

tommedema commented 6 years ago

@jdeanwaite not exactly sure but I suspect there is an issue related to path mapping and/or inclusion/exclusion of input files

reason is that your error contains an invalid path serverless-mono-example/packages/typesnode_modules where obviously it should be types/node_modules. There is a missing /.

Are you sure that node_modules is being excluded?

tommedema commented 6 years ago

I can now reproduce this issue. Not sure when it started appearing..

Not sure about a fix yet either. Will give it a try.

tommedema commented 6 years ago

@jdeanwaite problem is that the root tsconfig.json should not have a reference to types, because types is not supposed to be build. It only contains type definitions for compilation reasons used by typeRoots

However when removing it I'm seeing strange behavior where output files are not written to their outDirs. Will investigate further

tommedema commented 6 years ago

Fixed in https://github.com/tommedema/serverless-mono-example/commit/627ca9b8f36bf8b2c95e5484e318389a259c9c1d

justinwaite commented 6 years ago

Nice. Will check out the commit and massage it into my project.