Ts-loader: Strange behavior with Project References on

Created on 11 Sep 2019  路  18Comments  路  Source: TypeStrong/ts-loader

I have a project where I'm using [email protected] with projectReferences: true and following tsconfig:

{
  "extends": "xxx/typescript/tsconfig.json",
  "compilerOptions": {
    "composite": true,
    "incremental": true,
    "tsBuildInfoFile": "./.tscache/tsconfig.tsbuildinfo",
    "target": "es5",
    "module": "commonjs",
    "baseUrl": ".",
    "rootDir": "./src",
    "outDir": "./lib",
    "declaration": true,
    "declarationDir": "./lib",
    "typeRoots": [
      "./node_modules/@types"
    ],
    "paths": {
      "web-modules-core": [
        "../core"
      ],
    }
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx"
  ],
  "references": [
    {
      "path": "../core"
    },
  ]
}

The project is a lerna monorepository.

On first build I get error that web-modules-core can't be resolved. Even though web-modules-core package (located in ../core) builds itself during the startup.

If I stop webpack and start it again it succeeds...

pinned

Most helpful comment

I鈥檝e pinned it to keep the bot from marking it as stale again.

Keep in mind that ts-loader is maintained in the spare time of folks who have full-time jobs, and for many years, that has _overwhelmingly_ been @johnnyreilly. I can鈥檛 speak for him, but I don鈥檛 currently don鈥檛 have the time or energy to devote to this issue. I understand your frustration, but, I鈥檇 wager that any tool that lets @johnnyreilly volunteer his time to this project without it taking over his life and becoming unmanageable is a net win for the community.

Expressing your frustration is ok, and it鈥檚 useful to know people still care about this issue. I鈥檇 just also remind you that a) it鈥檚 not anybody鈥檚 job to do this, and b) it _can_ be _anybody鈥檚_ job to do this鈥攊t鈥檚 open source, and if you open a PR, I would make time to review it 馃檪

All 18 comments

Could you provide a minimal reproduction repo please?

cc @andrewbranch

@johnnyreilly @andrewbranch I can create a private repo and add you there if this would work.

In fact, I was able to make it clean enough to be public: https://github.com/kirill-konshin/wmc-ts-bug

$ npm install
$ cd storybook
$ npm start

Which consistently results in

ERROR in /Users/dis/Sites/wmc-ts-bug/storybook/src/stories/Well.tsx
./src/stories/Well.tsx
[tsl] ERROR in /Users/dis/Sites/wmc-ts-bug/storybook/src/stories/Well.tsx(4,20)
      TS2307: Cannot find module 'web-modules-core'.

Then Ctrl+C to stop.

Then again:

$ npm start

This time it will work just fine.

It looks like ts-loader does not understand that web-modules-core package has been built, so Project References part worked well, you can see build artifacts in core folder.

In order to clean everything up use npx lerna run clean which will remove all build artifacts.

Thanks @kirill-konshin!

Any luck so far @johnnyreilly ?

I'm not looking at this myself I'm afraid - completely snowed. It's possible it may be resolved by @sheetalkamat's work on https://github.com/TypeStrong/ts-loader/pull/1003

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Activity!

Do you know anything about this @andrewbranch? I haven't looked at this at all I'm afraid..

I filed a similar bug a while ago: https://github.com/TypeStrong/ts-loader/issues/1005 and I'm just now getting back to trying to implement project references again. As you state the first build fails but still produces the referenced projects definition files. Thats why the second build succeeds because those definition files are available at the onset of the compilation the second time around. It seems like a race condition or caching issue on ts-loader's part since the project references work just fine using tsc --build

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

For the community the stale bots and friends are the worst thing ever :/

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Let's notify everyone just for fun and stale bot. Do you like it, do you? I don't know why @johnnyreilly think that stale bot is a good idea.

I鈥檝e pinned it to keep the bot from marking it as stale again.

Keep in mind that ts-loader is maintained in the spare time of folks who have full-time jobs, and for many years, that has _overwhelmingly_ been @johnnyreilly. I can鈥檛 speak for him, but I don鈥檛 currently don鈥檛 have the time or energy to devote to this issue. I understand your frustration, but, I鈥檇 wager that any tool that lets @johnnyreilly volunteer his time to this project without it taking over his life and becoming unmanageable is a net win for the community.

Expressing your frustration is ok, and it鈥檚 useful to know people still care about this issue. I鈥檇 just also remind you that a) it鈥檚 not anybody鈥檚 job to do this, and b) it _can_ be _anybody鈥檚_ job to do this鈥攊t鈥檚 open source, and if you open a PR, I would make time to review it 馃檪

Don't get me wrong. It was sarcastic. I'm not frustrated about no movement in this issue. But I'm very frustrated about stale bot virus in open source space. I bored to say "I'm interested to leave this issue open" and spam every subscriber or be spammed from other people who comment issues just to let it alive. From my point of view, there is no point to have stale bot - close issue or let it open. But please, stop this virus.

But, well, thanks for pinning the issue.

This seems to have been fixed by PR #1136 by @sheetalkamat. This was to fix #1114 which had the same symptoms you reported. Your repo does not seem to have the symlinks present in #1114, which were reported to be causing the issue. However, the changes made to fix that issue may have also fixed yours.

I cloned your wmc-ts-bug repo, upgraded ts-loader to 8.0.0 and typescript to 3.9.3. It then builds and runs without error.

Fantastic! Thanks for investigating @appzuka! Sounds like we can close this then.

Was this page helpful?
0 / 5 - 0 ratings