Skip to content
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

CreateReactApp: Module not found on build #3761

Closed
fuwywawyuh opened this issue Aug 26, 2019 · 25 comments · Fixed by #3767
Closed

CreateReactApp: Module not found on build #3761

fuwywawyuh opened this issue Aug 26, 2019 · 25 comments · Fixed by #3767
Labels

Comments

@fuwywawyuh
Copy link

Hey,

This

./node_modules/semantic-ui-less/semantic.less
ModuleNotFoundError: Module not found: Error: Can't resolve './definitions/elements/themes/default/assets/images/flags.png' in 'C:\Users\user_\portfolio-app\node_modules\semantic-ui-less'

has been happening to me in my create-react-app and I couldn't figure out what to do. I've started a new project, from scratch and this happened again so I believe I could either be missing a step, or there's a bug?

I've create a react app from scratch, installed semantic-ui-react, installed semantic-ui-less with craco and updated the package.json file. I've also included craco.config (should this be in /src?).
I've also installed semantic-ui-react/bootstrap package and updated the bottom of the theme.config file with the 4 lines, exactly as they are (should I be changing any values?)
I'm importing "import 'semantic-ui-less/semantic.less'" at the end of my index.js.

Did I miss anything?

Thanks

@welcome
Copy link

welcome bot commented Aug 26, 2019

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@layershifter
Copy link
Member

I've also installed semantic-ui-react/bootstrap package

You don't need to install this package, only run:

npx @semantic-ui-react/bootstrap

It's hard to understand what is missing, can you push your project to GitHub?

@fuwywawyuh
Copy link
Author

I've also installed semantic-ui-react/bootstrap package

You don't need to install this package, only run:

npx @semantic-ui-react/bootstrap

It's hard to understand what is missing, can you push your project to GitHub?

My apologies, that's what I meant by installing the package.
I found the issue is something to do with my theming. if I remove semantic.less import and replace it with semantic-ui-css then everything is fine. So I'm missing something in that process.

@layershifter
Copy link
Member

IDK, please push the code to repo...

@fuwywawyuh
Copy link
Author

fuwywawyuh commented Aug 27, 2019 via email

@victortrusov
Copy link

victortrusov commented Aug 27, 2019

Had same error on npm run build after updating packages:

"react-scripts": "^3.0.1" --> "^3.1.1"
"@craco/craco": "^5.2.4" --> "^5.3.0"
"craco-less": "^1.9.0" --> "^1.12.0"
"less": "^3.9.0" --> "^3.10.3"

fallback to previous versions solved the problem

@Volland
Copy link

Volland commented Aug 27, 2019

I have the same issue. looks like 3.1.1 react-scripts do some breaking changes

@Volland
Copy link

Volland commented Aug 27, 2019

"@craco/craco": "^5.3.0",
"craco-less": "^1.12.0",
"react-scripts": "3.1.1",

I do not have direct link to a less package

@layershifter
Copy link
Member

Investigated a bit, it's caused by react-scripts@3.1.0 and by this change: facebook/create-react-app#5829. And now it's clear why it fails only on build 😛

Will try to provide a proper fix tomorrow.

@fuwywawyuh
Copy link
Author

Investigated a bit, it's caused by react-scripts@3.1.0 and by this change: facebook/create-react-app#5829. And now it's clear why it fails only on build 😛

Will try to provide a proper fix tomorrow.

Glad to know, I thought I was going insane. Sorry I couldn't provide a build earlier.

Downgrading packages seems to work at the moment though if anyone else runs into this.

Thanks

@layershifter layershifter changed the title Module not found on build CreateReactApp: Module not found on build Aug 28, 2019
@layershifter
Copy link
Member

layershifter commented Aug 28, 2019

craco.config.js

-const { getLoader, loaderByName, throwUnexpectedConfigError } = require('@craco/craco')
+const { removeLoaders, getLoader, loaderByName, throwUnexpectedConfigError } = require('@craco/craco')
  overrideWebpackConfig: ({ context, webpackConfig }) => {
+   removeLoaders(webpackConfig, loaderByName("resolve-url-loader"))

@fuwywawyuh @Volland
Can someone try this and confirm that it works with react-scripts@3.1.1 properly?


BTW, I am going to publish our plugin to simplify craco.config.js.

@fuwywawyuh
Copy link
Author

craco.config.js

-const { getLoader, loaderByName, throwUnexpectedConfigError } = require('@craco/craco')
+const { removeLoaders, getLoader, loaderByName, throwUnexpectedConfigError } = require('@craco/craco')
  overrideWebpackConfig: ({ context, webpackConfig }) => {
+   removeLoaders(webpackConfig, loaderByName("resolve-url-loader"))

@fuwywawyuh @Volland
Can someone try this and confirm that it works with react-scripts@3.1.1 properly?

BTW, I am going to publish our plugin to simplify craco.config.js.

I have since downgraded my main project.

I have ran this into a project I was testing stuff out (which has practically 0 components etc, but has the same packages and had the error) and the build now runs successfully.

@victortrusov
Copy link

craco.config.js

-const { getLoader, loaderByName, throwUnexpectedConfigError } = require('@craco/craco')
+const { removeLoaders, getLoader, loaderByName, throwUnexpectedConfigError } = require('@craco/craco')
  overrideWebpackConfig: ({ context, webpackConfig }) => {
+   removeLoaders(webpackConfig, loaderByName("resolve-url-loader"))

Just updated react-scripts to 3.1.1 and tested your solution. Working perfect! Thanks!

@layershifter
Copy link
Member

@victortrusov thank you for confirmation 👍

I introduced @semantic-ui-react/craco-less plugin, now craco.config is one liner 🚀 I will continue to improve setup process to simplify it even more.

craco.config.js

module.exports = {
  plugins: [{ plugin: require('@semantic-ui-react/craco-less') }],
}

@rickysullivan
Copy link

I'm using a LESS mixin that is throwing a warning Inline JavaScript is not enabled. Is it set in your options?

Needs to allow options to be passed down to craco-less.

module.exports = {
  plugins: [
    {
      plugin: require("@semantic-ui-react/craco-less"),
      options: {
        lessLoaderOptions: {
          javascriptEnabled: true
        }
      }
    }
  ]
};

@rickysullivan
Copy link

rickysullivan commented Oct 22, 2019

https://gist.github.com/rickysullivan/e4b75f9a1f2ef77ba0ac733f9bb7395d

Passes pluginOptions down.

What do you think @layershifter?

@scorsi
Copy link

scorsi commented Nov 20, 2019

Hello @layershifter,

I had an old code base using old semantic-ui-react setup with webpack which now have a lot of vulnerabilities. I so changed everything to use CRA + CRACO + @semantic-ui-react/craco-less (without ejecting configurations).
I was looking for the repository of @semantic-ui-react/craco-less for posting the issue without success. Hope, this is the right place.

I need to use the CSS Modules (to avoid too much codebase changes), I so do in the craco.config.js file :

module.exports = {
  plugins: [{
    plugin: require('@semantic-ui-react/craco-less'),
    options: {
      cssLoaderOptions: {
        modules: true,
        localIdentName: '[local]_[hash:base64:5]',
      },
    },
  }],
};

But still got a weird issue.
If I use import * as styles from ... or import styles from ..., I got undefined values.
If I rename my style files to my-file-name.module.less (as hinted here : https://create-react-app.dev/docs/adding-a-css-modules-stylesheet), I got an error where the webpack loader seems to not recognized the file type : Module parse failed: Unexpected token (1:0). You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

Do you have any clue ?

@layershifter
Copy link
Member

You can temporary use craco-less for CSS modules: https://www.npmjs.com/package/craco-less#css-modules

It should work, can you please check?

@scorsi
Copy link

scorsi commented Nov 20, 2019

I already tried that but got a weird issue with semantic-ui-less files.

@import (multiple) '../../theme.config';
^
Can't resolve '../../theme.config' in '/somewhere/node_modules/semantic-ui-less/definitions/modules'
      in /somewhere/node_modules/semantic-ui-less/definitions/modules/transition.less (line 19, column 0)

Which is fixed by @semantic-ui-react/craco-less, right ?

@rickysullivan
Copy link

rickysullivan commented Nov 20, 2019

@layershifter Why not just allow pluginOptions to be passed down? See my gist.

@rickysullivan
Copy link

@layershifter thoughts?

@layershifter
Copy link
Member

@rickysullivan I will do a change with pluginOptions on next week 🚀

@rickysullivan
Copy link

@layershifter legend!

@layershifter
Copy link
Member

@rickysullivan released in @semantic-ui-react/craco-less@1.2.1 👍

I also created README.md files and added proper links to package.json files, so now it's clear where the source can be find 😺

@emutanen
Copy link

emutanen commented Jul 2, 2021

Not fully related to modules, but rickysullivan's solution gave me an idea for a fix to a problem where
CRA Typescript setup with SUI React complained that Error evaluating function unit: the first argument to unit must be a number. Here is the shown error with yarn start

Failed to compile.

./node_modules/semantic-ui-less/semantic.less (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-9-1!./node_modules/postcss-loader/src??postcss!./node_modules/less-loader/dist/cjs.js??ref--5-oneOf-9-3!./node_modules/semantic-ui-less/semantic.less)

@relativeLarge   : unit( round(@largeSize * @emSize) / @emSize, em);
@relativeBig     : unit( round(@bigSize * @emSize) / @emSize, em);
                 ^
Error evaluating function `unit`: the first argument to unit must be a number. Have you forgotten parenthesis?

The one-line CRACO config seems to not work in this particular setup with react-scripts 4.0.3 and semantic-ui-less 2.4.1 and semantic-ui-react 2.0.3.

I ended up changing the contents of craco.config.js to

 module.exports = {
  plugins: [
    {
      plugin: require("@semantic-ui-react/craco-less"),
      options: {
        lessLoaderOptions: {
          lessOptions: {
            math: "always",
            javascriptEnabled: true,
          },
        },
      },
    },
  ],
};

Now it works perfectly, thanks for the idea to work with the craco config file!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants