sanity icon indicating copy to clipboard operation
sanity copied to clipboard

Not working with Nx

Open ajereos-circadence opened this issue 4 years ago • 2 comments

I'm using Nx as monorepo, seems tsconfig only works in the editor but not when on dev or build. My guess is, this is related to webpack. Hope anyone solved this issue.

To Reproduce

  1. create new app for sanity
  2. create shared lib
  3. include shared lib to sanity

Expected behavior

It should work as the editor, but it's not.

Which versions of Sanity are you using?

Recent

Which versions of Node.js / npm are you running?

14.17.4

ajereos-circadence avatar Oct 24 '21 04:10 ajereos-circadence

You're right that this is related to Webpack, using some custom Webpack configuration might help to work around this.

There is an issue open for customizing the Webpack config here: https://github.com/sanity-io/sanity/issues/1609, and one of the comments points to a solution for customizing the Webpack config: https://github.com/sanity-io/sanity/issues/2092#issuecomment-1004517695

Based on these comments I got it to work with the following steps.

Install dependencies:

$ npm install tsconfig-paths-webpack-plugin [email protected]

Add webpack.sanity.js file to your studio app's root folder apps/{appName}:

const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = function (config) {
  config.resolve = config.resolve || {};
  config.resolve.plugins = config.resolve.plugins || [];

  config.resolve.plugins.push(new TsconfigPathsPlugin());

  return config;
};

Since this can be resolved easily enough I think the issue can be closed. Although I think the docs should be updated with details on how to use custom Webpack configuration.

nathanosdev avatar Jan 13 '22 21:01 nathanosdev

any update on this for v3?

simonpeters avatar Aug 18 '22 12:08 simonpeters

Studio v3 is bundler-agnostic and introduces Vite as its new default bundling tool. You should probably have luck with it!


We are currently working on improving our workflows and follow-up on our open GitHub repository. In that work, we have decided to close most issues older than the release of Sanity Studio v3.

We value your feedback, so if this issue is still important to you and relevant for Sanity Studio v3, please search for relevant open issues. If you can’t find any, open a new one and link to relevant comments in this thread. For questions about how to do something, please post them in the slack community.

kmelve avatar Jan 13 '23 09:01 kmelve

@ajereos-circadence Hi, Any workaround to use sanity inside of a Nx monorepo? Currently I don't find a solution to do it ?

nestorbfgo avatar Mar 04 '24 15:03 nestorbfgo