sanity
sanity copied to clipboard
Not working with Nx
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
- create new app for sanity
- create shared lib
- 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
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.
any update on this for v3?
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.
@ajereos-circadence Hi, Any workaround to use sanity inside of a Nx monorepo? Currently I don't find a solution to do it ?