dsherret / dsherret/ts-morph

Uncaught TypeError when i dont run "npm run bootstrap"

Open
#1,349 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

when i naively run `npm run build`
then the `common` package fails to build

```sh
cd $(mktemp -d)
git clone --depth 1 https://github.com/dsherret/ts-morph
cd ts-morph/
pnpm import package-lock.json
pnpm install
npm run build
```

```
error: Uncaught TypeError: Cannot read properties of undefined (reading 'getSourceFile')
else if (declarations[0].getSourceFile().isInNodeModules()) {
^
at file:///home/user/src/ts-morph/ts-morph/packages/common/scripts/buildDeclarations.ts:23:28
```

```
> @ts-morph/main@0.0.0 build
> lerna run build

lerna notice cli v5.0.0
lerna info versioning independent
lerna info Executing command in 3 packages: "npm run build"
lerna ERR! npm run build exited 1 in '@ts-morph/common'
lerna ERR! npm run build stdout:

> @ts-morph/common@0.17.0 build
> npm run build:declarations && npm run build:node && npm run build:deno

> @ts-morph/common@0.17.0 build:declarations
> deno run -A scripts/buildDeclarations.ts

lerna ERR! npm run build stderr:
Download https://deno.land/x/dts_minify@0.3.0/mod.ts
Download https://deno.land/std@0.140.0/path/mod.ts
...
Download https://deno.land/std@0.128.0/path/separator.ts
Download https://deno.land/std@0.128.0/path/win32.ts
Download https://deno.land/std@0.128.0/path/_constants.ts
Download https://deno.land/std@0.128.0/path/_util.ts
error: Uncaught TypeError: Cannot read properties of undefined (reading 'getSourceFile')
else if (declarations[0].getSourceFile().isInNodeModules()) {
^
at file:///home/user/src/ts-morph/ts-morph/packages/common/scripts/buildDeclarations.ts:23:28
lerna ERR! npm run build exited 1 in '@ts-morph/common'
```

https://github.com/dsherret/ts-morph/blob/f927d01b347b14a667df0334ea974e7133a963d0/packages/common/scripts/buildDeclarations.ts#L20-L23

```
deno --version

deno 1.25.4 (release, x86_64-unknown-linux-gnu)
v8 10.7.193.3
typescript 4.7.4
```

### the right way

> when i naively run `npm run build`

the right way is `npm run bootstrap`

https://github.com/dsherret/ts-morph/blob/f927d01b347b14a667df0334ea974e7133a963d0/DEVELOPMENT.md?plain=1#L1-L8

which is

https://github.com/dsherret/ts-morph/blob/f927d01b347b14a667df0334ea974e7133a963d0/package.json#L7

which also works with `pnpm install`

```
pnpm install
npm run bootstrap
npm run build
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the commands in the issue, then inspect packages/common/scripts/buildDeclarations.ts around line 23. Compare the direct npm run build path with the documented npm run bootstrap flow in DEVELOPMENT.md and package.json. Done means the build no longer throws the reported TypeError or the required bootstrap step is clearly enforced.

Written by the indexing model from the issue text.

Assessment

Tech stack
deno, typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.