-
-
Notifications
You must be signed in to change notification settings - Fork 433
Module not found
when using raw-loader and project references
#1127
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
Comments
You are not actually using project references in this example. You are just building using webpack and the first command fails because in test/tsconfig.json you only include "*". If you change the include statement to:
then it builds as expected. If you want to use project references you will set it up so that when the project builds ts-loader will cause tsc to build dependent projects. Then webpack will use the output of those projects in its build without rebuilding them, unless necessary. In your repo, src is the referenced project. Test is not a project reference; it references src. tsconfig in src should look something like:
When you run
tsc will build the project src and the output will be in src/out. Your test project can then import the files from src/out. ts-loader should automatically rebuild referenced projects if they change (although there is currently an issue with this. See #1114). This will only happen if you set projectReferences: true in the ts-loader options in your webpack config. When you build src with the tsc command above it does build the project and put the output in src/out. However, tsc does not know about raw-loader so it just includes the import statement
in the emitted file. It ignores the .frg and .vtx files as tsc does not understand these. Then, when webpack builds test using the pre-built output in src/out it throws an error because ./shad/foo.frg is not in src/out. If you want to use webpack loaders in dependent projects you will need to build them as sub-projects using webpack. You can see a simple repo using project references at the repo in issue 1114: https://github.com/jedster1111/ts-loader-project-references This shows how project references work with ts-loader. There is currently an issue where the project needs to be built twice to succeed although that is being worked on. |
@trbabb @appzuka this appears like a solution https://stackoverflow.com/questions/50469875/configuring-typescript-to-work-with-html-modules edit: actually it would be nice to have a solution that doesnt require naming the imported modules differently. |
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. |
afaik still an issue stale-bot. |
@nebulousdog, please explain what is still an issue, with a minimal repo if possible. |
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. |
Closing as stale. Please reopen if you'd like to work on this further. |
Expected Behavior
When using Webpack's
raw-loader
with TypeScript project references— For any given moduleX.ts
, I'd expect import paths relative toX.ts
to refer to the same resources whetherX
is imported from within its own project, or from a module in a different project.Specifically, if X.ts successfully finds a resource Y, both contained in project Z when Z is compiled separately, then I wouldn't expect Y to suddenly be considered missing when Z is imported or referenced by another project.
Clone https://github.com/trbabb/rawloader-repro.git, and after
npm install
, runnpx webpack
. I'd expectsrc/Foo.ts
to find./shad/foo.frg
and import it normally.Actual Behavior
npx webpack
in the above repo yields:This is not the case if
src/Foo.ts
is compiled from within its own project. This can be seen if you:This compiles normally, and the contents of
foo.frg
can be found inside the bundle as expected.Somehow, the existence of project reference breaks the relative path in
src/Foo.ts
.Code / How to reproduce
The raw-loader team informs me that this is likely a ts-loader issue. I'm not well versed in how different loaders interact with each other— please let me know if there's relevant information to pass back to the raw-loader team, or if there's anything I need to configure differently to get this to work.
Thanks!
The text was updated successfully, but these errors were encountered: