-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Compilation error with react-scripts 4.0.0 ( Can't resolve file ) #9870
Comments
Having a similar issue but with sass |
What does the import line look like? What kind of file is it in? I had the same |
@jrr I'd like to move the images to |
I have the same problem with SCSS and CSS files (images and fonts). In 3.x.x works but now it says it can't resolve the file in src. |
I also have a problem when loading fonts from public folder. It did work in 3.x.x |
I had this error on a project that was using absolute imports. It seems like setting
|
I'm also seeing this issue where we have an image in
Error:
|
Can confirm this happens with @font-face {
font-family: 'Nunito';
font-style: normal;
font-weight: normal;
font-display: swap;
src: local('Nunito Bold'), local('Nunito-Bold'), url('/fonts/nunito.woff2') format('woff2');
} ./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
Error: Can't resolve '/fonts/nunito.woff2' in '/Path/To/Project/src' Edit: I dug into the changelog and It looks like this is caused by the Originally, a root-relative path like |
We are using another repo folder for the assets. I'm getting an error:
Error: Can't resolve '../../assets/iphone.svg' in '.../src/components/HTMLPreview' How can I disable this validation and use this path? |
This comment has been minimized.
This comment has been minimized.
@x5engine What? Who is "you"? Edit: The 👎 urges me to clarify that the question Who is "you"? could be replaced with Who has not even mentioned this anywhere? |
Chill. Also, this is a major update. That implies breaking changes. |
This comment has been minimized.
This comment has been minimized.
Yeah man I was going nuts. Hope this gets sorted out soon 🙂 |
running the same issue... waiting for clues |
If you care to dive into the react-scripts webpack setup, you can pass in the option to disable url routing to css-loader. In
to
Of course this entails all the issues that come around with modifying the config inside of node_modules, but hopefully this might help in a long term fix for the change in css-loader resolving the urls. |
Looking at You would have to include |
For those used to diff --git a/node_modules/react-scripts/config/webpack.config.js b/node_modules/react-scripts/config/webpack.config.js
index 80c6ac2..01de68e 100644
--- a/node_modules/react-scripts/config/webpack.config.js
+++ b/node_modules/react-scripts/config/webpack.config.js
@@ -117,7 +117,7 @@ module.exports = function (webpackEnv) {
},
{
loader: require.resolve('css-loader'),
- options: cssOptions,
+ options: {...cssOptions, url: false},
},
{
// Options for PostCSS as we reference these options twice
Edit: Actually, that workaround only solves the issue in development ( |
I had an issue loading fonts from within CSS. But thanks to @evilebottnawi pointing out how webpack/css-loader@4+ resolves URLs i was able to fix my issues:
I use rsuite as a UI framework. To override default icon font settings you can set a
- @import '../../../../node_modules/rsuite/lib/styles/themes/default/core';
+ @import './node_modules/rsuite/lib/styles/themes/default/core';
- @icon-font-path: '/fonts/rsuite-icon';
+ @icon-font-path: './fonts/rsuite-icon'; My icon font is located in Maybe this helps by getting the idea of how URLs are resolved. Edit: Forgot to mention how
Edit: Oh my, what was i thinking... I wasn't aware of a faulty configuration because of working fallback mechanisms i didn't notice. I had to update my
and had to roll back like this + @icon-font-path: '/fonts/rsuite-icon';
- @icon-font-path: './fonts/rsuite-icon'; This way URLs in CSS won't be handled by webpack and you can use them like you would in regular CSS & HTML, if i got that straight. If you do not rely on webpack handling URLs in CSS this could be an option for you. I had to remove the |
I have the same issue. |
In recent commits, we upgraded our react-scripts version from 3.4.4 to 4.0.3. This is because CRA (create-react-app) v3 uses an outdated version of eslint (facebook/create-react-app#8849). This introduced a bug related to the css-loader library, which can no longer resolve assets in the public folder: - facebook/create-react-app#9870 (comment) - webpack-contrib/css-loader#1136 (comment) This commit fixes this bug by moving the referenced image to the relevant sub-directory in the src directory.
* fix: outdated packages with vulnerabilities * feat: install eslint and initiate config * feat: install prettier and set prettier options * feat: install eslint-config-prettier * feat: install eslint-plugin-prettier * chore: reformat eslint config * feat: add @trivago/prettier-plugin-sort-imports, define preferred import order * fix: css-loader file resolution bug introduced by CRA v4 In recent commits, we upgraded our react-scripts version from 3.4.4 to 4.0.3. This is because CRA (create-react-app) v3 uses an outdated version of eslint (facebook/create-react-app#8849). This introduced a bug related to the css-loader library, which can no longer resolve assets in the public folder: - facebook/create-react-app#9870 (comment) - webpack-contrib/css-loader#1136 (comment) This commit fixes this bug by moving the referenced image to the relevant sub-directory in the src directory. * chore: temporarily disable eslint * chore: add more files and folders to .prettierignore * chore: upgrade prettier-plugin-sort-imports to 2.0.2 fixes trivago/prettier-plugin-sort-imports#22 * chore: temporarily disable prettier * chore: remove prettier config temporarily * chore: remove jsx-a11y references temporarily * temporarily remove import/prefer-default-export reference Co-authored-by: jiehao <[email protected]> Co-authored-by: Preston Lim <[email protected]>
* fix: outdated packages with vulnerabilities * feat: install eslint and initiate config * feat: install prettier and set prettier options * feat: install eslint-config-prettier * feat: install eslint-plugin-prettier * chore: reformat eslint config * feat: add @trivago/prettier-plugin-sort-imports, define preferred import order * fix: css-loader file resolution bug introduced by CRA v4 In recent commits, we upgraded our react-scripts version from 3.4.4 to 4.0.3. This is because CRA (create-react-app) v3 uses an outdated version of eslint (facebook/create-react-app#8849). This introduced a bug related to the css-loader library, which can no longer resolve assets in the public folder: - facebook/create-react-app#9870 (comment) - webpack-contrib/css-loader#1136 (comment) This commit fixes this bug by moving the referenced image to the relevant sub-directory in the src directory. * chore: temporarily disable eslint * chore: add more files and folders to .prettierignore * chore: upgrade prettier-plugin-sort-imports to 2.0.2 fixes trivago/prettier-plugin-sort-imports#22 * chore: temporarily disable prettier * chore: remove prettier config temporarily * chore: remove jsx-a11y references temporarily * temporarily remove import/prefer-default-export reference Co-authored-by: jiehao <[email protected]> Co-authored-by: Preston Lim <[email protected]>
* Add linting and formatting tools (#378) * fix: outdated packages with vulnerabilities * feat: install eslint and initiate config * feat: install prettier and set prettier options * feat: install eslint-config-prettier * feat: install eslint-plugin-prettier * chore: reformat eslint config * feat: add @trivago/prettier-plugin-sort-imports, define preferred import order * fix: css-loader file resolution bug introduced by CRA v4 In recent commits, we upgraded our react-scripts version from 3.4.4 to 4.0.3. This is because CRA (create-react-app) v3 uses an outdated version of eslint (facebook/create-react-app#8849). This introduced a bug related to the css-loader library, which can no longer resolve assets in the public folder: - facebook/create-react-app#9870 (comment) - webpack-contrib/css-loader#1136 (comment) This commit fixes this bug by moving the referenced image to the relevant sub-directory in the src directory. * chore: temporarily disable eslint * chore: add more files and folders to .prettierignore * chore: upgrade prettier-plugin-sort-imports to 2.0.2 fixes trivago/prettier-plugin-sort-imports#22 * chore: temporarily disable prettier * chore: remove prettier config temporarily * chore: remove jsx-a11y references temporarily * temporarily remove import/prefer-default-export reference Co-authored-by: jiehao <[email protected]> Co-authored-by: Preston Lim <[email protected]> * Fix/resource color (#430) * fix: resource page header changed to bg-secondary * fix: using isResourcePage to determine page header * Fix/rearrange layout (#427) * fix: simplify directoryFile utils for retrieve and update * fix: update methods using directoryFile utils * fix: introduce FolderReorderingModal * fix: refactors FolderContent * fix: update params for FolderContentItem * fix: fix breadcrumb display * fix: add propTypes for FolderReorderingModal * fix: add Cancel button to FolderReorderingModal * fix: updates draggable-id for React dnd * fix: updates dropdown button behavior for reordering * fix: updates copy text * fix: updates copy text * fix: updates variable naming for directory file output * refactor: clean up ProtectedRoute and LoginContext (#431) * refactor: clean up ProtectedRoute and LoginContext * refactor: make LoginContext testable create 3 exports: LoginContext itself, LoginProvider, LoginConsumer * refactor: make route selector testable in App.jsx * refactor: group routing components * feat: add basic routing tests * refactor: move __tests__ folder to correct place Required for jest to find the test files * style: delete unnecessary div * refactor: make exports more obvious for LoginContext.js * refactor: delete duplicate route * chore: add rest of routing tests * style: remove unused declarations * Fix/fine-tune react-query settings (#389) * fix: turn off refetching on window focus for useQuery This commit sets the `refetchOnWindowFocus` flag for the useQuery on the following layouts/components to be `false`: - PageSettingsModal - EditNavBar - EditPage The reason we turn off this flag is because these pages involve user changes - with this flag on, any unsaved changes by the user would be overwritten by the refetched data. This commit also sets the - `refetchOnReconnect` - `refetchInterval` - `refetchIntervalInBackground` flags to be false for the same reasons explained above. * fix: invalidate queries after mutation This commit adds cache invalidation of all our GET queries (the useQuery invocations) after we perform a mutation. This allows us to reset our cache in a more granular manner, as opposed to simply setting the cache time for our GET queries to be 0. Additionally, this commit also adds a PAGE_SETTINGS_KEY constant to replace the string literal that was being used as the query key for the PageSettingsModal. Refer to the following documentation for more details: - https://react-query.tanstack.com/guides/query-invalidation - https://react-query.tanstack.com/guides/invalidations-from-mutations * feat: standardize output of GET API calls to return resp.data This commit standardizes the output of our GET API functions to return resp.data instead of just the response from the api call. resp.data is a better choice as we are able to use that in dependency arrays, whereas the resp object pointer always changes, which will trigger the useEffect every time even if the object data hasn't actually changed. * fix: load yaml content when reading directory file * feat: disable useQuery if component tracks local state As per our discussion (refer to meeting minutes here: https://docs.google.com/document/d/1br6T6wVX0KrcA3nwQEo7OhUrcT4veLnaz0vByEXjVvo/edit#heading=h.hyx8t36v9z3n) we will be discussing our `useQuery` functions if there are changes to the local state that are being tracked, to avoid refetching behavior from overwriting local changes. * fix: rebase errors * fix: invocation of LoginContext * Fix: rebase errors * Fix: update resource category and resource page get calls to return data directly * Refactor: use invalidateQueries instead of passing refetch function for CollectionPagesSection * Fix: error when retrieving page settings * Fix: rebase errors * Fix: invalidate query instead of reload when changing page settings * Feat: add success toast when changing settings * Fix: change folder naming to use invalidation instead of reload * Fix: invalidate correct resource folder key * Fix: update success toast messages * Fix: remove log statement * Fix: add successtoast Co-authored-by: Alexander Lee <[email protected]> * fix: pass parameters to wrapped components (#439) * fix: fixes toast popup on item select, folder deletion modal (#440) * fix: fixes toast popup on item select, folder deletion modal * fix: add condition for folder deletion Co-authored-by: kwajiehao <[email protected]> Co-authored-by: jiehao <[email protected]> Co-authored-by: Preston Lim <[email protected]> Co-authored-by: Alexander Lee <[email protected]> Co-authored-by: Alexander Lee <[email protected]>
The public folder was supposed to serve files during development which
Is this not the case anymore? |
If anyone wishes to keep files in public folder (as for various reasons) see my answer on SO how to make it work with CRA 4.0.x and craco |
Worked for my finally after 3 days long struggle. Thanks |
@mghazanfar this will disable all url resolving. We wanted only to not resolve urls from ...
options: {...cssOptions, url: url => !url.startsWith("/.resources")},
.... That way other urls that you use inside your scss files in components will still resolve. |
./src/components/Home/Header/Header.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/components/Home/Header/Header.css) I GOT THE SAME ERROR. I CAN'T ACCESS public FOLDER IMAGES FROM ANY .css FILE. |
having this issue with |
Thanks to chriswininger. I could resolve my issue following his advice. I changed the syntax of quotes from url('/images/img-2.jpg') to 'url(/images/img-2.jpg)' in my App.css file |
I wanted to load a background image from Tailwind, but I got the error "./src/index.css Error: Can't resolve '/img...", CRA comes with "@craco/craco": "^6.4.0", and "react-scripts": "4.0.3", for these versions, it doesn't work to load the image with the relative path. Performing @ejose19's workaround works but it is not ideal. My solution was to downgrade the versions of "@craco/craco":"^5.6.0" and "react-scripts":"^3.3.0-next.38" and it worked without problems. What a way to waste time... |
This works localy but if you deploy your app with netlify for instance it would crash because the node_modules is no shipped to the server before builds. |
I can't believe this is still an issue. Setting This will solve the issue given the following folder structure:
This will run the patches after every install. You can (and should) commit these files to the repository. |
This worked for me. So /path-to-file in the url() will be resolved as /src/path-to-file |
https://github.com/facebook/create-react-app/releases/tag/v5.0.0 Some excerpts from the official docs related with this issue: Using the Public Folder | Create React App
Adding Images, Fonts, and Files | Create React App
I used the "patch" approach in some projects for a while but finally switched to the relative path approach (by moving images into |
Doesn't this mean that they'll be included in the production build? My understanding was that the public folder served assets which a) are available in prod environments and thus don't need to be included in the dev build. |
Thank you for your comment. Personally speaking, I don't think it's an intended use case but I'm not sure, it's just my understanding... |
Just hit this issue today, when i upgraded react-scripts in my app. I am moving forward with this one. I think this is the best way to go now, because adding more and more configurations ( which will be fixed in the near future ) would not be the best idea. |
This solution solved the issue for me. I think this is the best way. |
This is still an issue for me |
- Cannot import from public folder, so move to src folder - Reorg components into folders facebook/create-react-app#9870
@alihesari 's solution worked perfectly for me. |
latest update of react-scripts to 4.0.0 from 3.4.4 causes a compilation problem.
With 3.4.4 it works, and the file exists
The text was updated successfully, but these errors were encountered: