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
Workspace Schematics: importing a TS file outside the "tools" directory causes a TS error #2536
Comments
tools
directory breaks
When we run workspace schematics we use the tsconfig in the tools directory. This file has a property called You can try changing some of the settings in the |
Ok, I've tried removing the rootDir but that results in the underlying Nx script not being able to copy over some of the resulting files. I'll keep playing with it. |
Hey, thx for reporting this. I'll give it a look tomorrow |
I'm having similar problem. I'd like to use some utility functions in my schematic and they cannot be imported because workspace-schematic script breaks. |
I'm also experiencing this behavor importing |
Still an issue? Because I'm still getting this error. |
I encountered this today, did anyone find a workaround? |
@Tiedye It's a bit hacky, but I was able to work around this (until it gets fixed) by using a global require statement. For example, if you need to import a Before
After
... note that the extra |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Sure seems like this still may be a problem... anyone with ideas about a fix. Real easy to create a generator / schematic that attempts to import a nx library into the new application, and ultimately fail when running because of this. |
I found that templated ts files in the generator/schematic were being compiled when they shouldn't be. They had been excluded in tsconfig.base.json as I updated tsconfig.base.json to exclude |
I also would like to be able to use a generator from another generator of the same monorepo 👍 |
I would like to do the same as @hadrien-toma |
Is there any reason why workspace generators are not build in the same way as the apps? It could solve this issue as well as #5548 and allow to have different tsconfig for generators if needed. |
This is kind of annoying. Why was this decision made? We have many utility functions in |
Same on our side, we have a bash script to do the copy and need to rerun it each time we need to propagate a change from generator A to generator B (generator B using generator A) |
I have the same problem. Can't use "libs/" inside "tools/" |
I have the same problem too, I should be able to import libs I've created |
Me too, i cannot access a lib from a workspace-schematic |
Still no reason to why we can't use libs inside our generators? |
The common use case for this (using a workspace library from a workspace generator) should be solved by #9116. One thing to note is that it doesn't solve it for current workspace generators, but migrating those into a local plugin library (perhaps named workspace or similar) and calling them with After this use case is solidified and battle-tested, we may consider migrating existing workspace generators into a similar setup. |
I'm going to close this out, since its addressed in the local plugin functionality. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Expected Behavior
I should be able to import a TS file from an app or lib into my custom workspace schematic and use it.
Current Behavior
When I try importing a file from an app or lib into my custom schematic, I get a
'rootDir' is expected to contain all source files
TS error.Failure Information (for bugs)
Steps to Reproduce
The specific steps to reproduce are as follows:
npx create-nx-workspace@latest schematics-playground
Angular
as the type of workspacedefault
test
schematic viang g workspace-schematic test
index.ts
file for that schematic, import theapp.module.ts
for thedefault
app that was generated (or really any file that requires traversal outside of thetools
directory)./node_modules/.bin/nx workspace-schematic test
Context
nx report
Reproduction
A minimal reproduction of the error can be found here.
This was generated using the exact steps outlined in "Steps to Reproduce".
Just install dependencies and run the
test
schematic vianx workspace-schematic test
.Failure Logs
In the repro I am trying to import the
AppModule
fromapps/default/src/app/app.module.ts
into my schematic attools/schematics/test/index.ts
and it results in this error:Other
For reference, here is the resulting structure of the
dist
folder when I run the schematic and get the error:Almost positive the error is coming from this function, because I tried running the
tsc -p tools/tsconfig.tools.json
command myself and got the same error.The text was updated successfully, but these errors were encountered: