-
Notifications
You must be signed in to change notification settings - Fork 492
Sharing code between multiple projects #260
Comments
Can you be a bit more precise on this, i.e. provide the error output? |
I don't actually have them on hand, unfortunately - I've kept iterating as the day went on. When importing a named export ( |
if that isn't enough info, feel free to close the issue. I'd understand |
I'd be happy to help, but without any reproduction project or at least the error message(s), it's hard to figure something out. |
Lemme see if I can reproduce it - I have more time today than yesterday |
Hm... are you sure this repo illustrates the error you're receiving? I don't get any, though.
=> No errors in terminal, and app works fine. |
the 'shared' folder contains two files (jstest.js and tstest.ts) each with identical code. Each file exports two strings, one as a named export and one as a default export. I try to reference all 4 of the strings in App.tsx but only the strings exported from jstest.js make it through. The named TS export is replaced by what appears to be a partial file path, and the default export is replaced by undefined |
Hm, I see. This is what I get when logging these entries (same order as in your code):
The last entry is a file path generated by
But beware of the potential side-effects this might have - see https://webpack.js.org/configuration/resolve/#resolve-symlinks. |
I suppose I could also fork your version of react-scripts... but whatever I end up doing, thank you so much for your help with this and all the work you've done on this project! |
@JNaftali I just ran into this problem and was about to create an issue for it. |
It seems like webpack doesn't like symlinks: webpack/webpack#1643 They recommend we share code with yarn/lerna workspace. CRA support for workspace already landed on 2.0: facebook/create-react-app#3815 So we should get it when CRA 2.0 is merged?, IIUC. |
My work hasn't started on the project for which we require this, so we haven't settled on an answer yet. We're not too enthused about workspaces so we're considering using git submodules. Another alternative is making sure TS transpiles dependencies and declaring that folder as a dependency (stackoverflow link) |
I've implemented a workaround using tsc's baseUrl which CRA-ts already supported. https://github.com/untsamphan/cra-ts-monorepo-example Need to eject (only) if you want tsc/webpack to grab .ts from the local packages. Steps
|
Now that TypeScript 3.0 introduced project references, it looks like we just need to wait for See TypeStrong/ts-loader#815 for reference. |
Looks like ts-loader has support for this now (815 is closed) |
when one issue closes, another one opens - TypeStrong/ts-loader#851 |
Hello. I'm trying to prototype sharing TS code between a web and a react-native application. At the moment my directory structure looks like this:
Working inside of App.tsx, if I try to
import { foo } from './shared/x.js'
I can do so without any trouble. However if I try toimport { foo } from './shared/x.tsx'
I get errors that make it sound like x.tsx is not getting compiled.Any advice on how to solve this issue? Ideally by teaching ts to properly resolve symlinks.
The text was updated successfully, but these errors were encountered: