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

Flow reports "Required module not found" when requiring a .scss file via Webpack #338

Closed
gcazaciuc opened this issue Mar 24, 2015 · 15 comments

Comments

@gcazaciuc
Copy link

Using Webpack for build management and an example file like:

require('../css/seed-component.scss');

var React = require('react');

var SeedComponent = React.createClass({
getInitialState: function() {
return { 'data' : 'Seed Component' };
},
render: function(): ?ReactElement {
return (


Header for Seed component

{this.state.data}
Component props

{this.props.name}

);
}
});

When running Flow over it it complains about the line "require('../css/seed-component.scss');" throwing an error "Required module not found" . I believe Flow should check that it's dealing with a JS file before throwing this error since in webpack it is common to require css files and images.
Currently this is a showstopper for me on using Flow and Webpack on a large project. Any suggested work-arounds ?

Thanks!

@tcoopman
Copy link
Contributor

I believe this is a duplicate of #51?

@gcazaciuc
Copy link
Author

Indeed, thanks. But still, are there any work-arounds for the issue ?

@johnryan
Copy link

@gcazaciuc Did you ever find a solution to this?

I'm using import styles from './Login.scss';

and getting an error. However, for another (regular css file) it works fine:
import styles from './regular_style.css';

@gcazaciuc
Copy link
Author

you just need to make sure that the module.name_mapper setting in flowconfig contains mappings for scss file extension and is mapping it to a dummy module.

@marianna-exelate
Copy link

marianna-exelate commented Feb 1, 2017

Hi,
Can you please be more specific what dummy module configuration is?

@Malax
Copy link

Malax commented Feb 7, 2017

@marianna-exelate You can find the documentation about that here: https://flowtype.org/docs/advanced-configuration.html#options

It's basically telling flow to treat such imports (like SCSS files) as another import which flow can actually understand. "Dummy module" just means that that module does not actually do anything besides being there to please flow.

sea-witch pushed a commit to buildit/bookit-web that referenced this issue Mar 23, 2017
- Demo a very simple example of Flow usage in RoomLabel/index.js
- Modify ESLint config to play nice with Flow. See: https://github.com/gajus/eslint-plugin-flowtype and http://stackoverflow.com/questions/36258234/eslint-with-arbnb-config-and-facebook-flow-together
- Trick Flow into playing nice with scss module imports. See: facebook/flow#338
@rofrol
Copy link

rofrol commented Oct 3, 2017

in .flowconfig

[options]
module.file_ext=.css
module.name_mapper.extension='css' -> 'empty/object'
module.file_ext=.scss
module.name_mapper.extension='scss' -> 'empty/object'

https://gist.github.com/lambdahands/d19e0da96285b749f0ef

@patrykkarny
Copy link

patrykkarny commented Dec 6, 2017

@rofrol your solution kills the flow type checking in all *.js, *.jsx files, it should be:

[options]
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.css
module.file_ext=.scss
module.name_mapper.extension='css' -> 'empty/object'
module.name_mapper.extension='scss' -> 'empty/object'

Link for docs
https://flow.org/en/docs/config/options

@jantoebes
Copy link

jantoebes commented Dec 14, 2017

@patrykkarny @rofrol

patrykkarny is totally right, it took a while before I discovered that the solution ignores all js type checks

@tomalexhughes
Copy link

For those looking for documentation, a lot of the above links are either broken or the pages have been updated. This page currently has information on the module.name_mapper option.

@xuqinggang
Copy link

added all the file types I wanted flow to recognize: in .flowconfig file

[options]
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.css
module.file_ext=.less
module.file_ext=.scss

@zaytsev-mxm
Copy link

zaytsev-mxm commented Oct 20, 2018

@patrykkarny thanks, it works — that setting stops flow from showing errors on import of scss files — but now is displays tons of error directly in scss-files, like this:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/desktop/routes/register/Register.scss:1:1

Unexpected token .

     1│ .root {
     2│   padding-left: 20px;
     3│   padding-right: 20px;
     4│ }

Looks like flow tries to import these files content as is – but webpack is configured to load them es ES modules
I have no idea how to fix that – may be you have any thoughts?

@spaquis
Copy link

spaquis commented Dec 1, 2018

@patrykkarny thanks, it works — that setting stops flow from showing errors on import of scss files — but now is displays tons of error directly in scss-files, like this:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/desktop/routes/register/Register.scss:1:1

Unexpected token .

     1│ .root {
     2│   padding-left: 20px;
     3│   padding-right: 20px;
     4│ }

Looks like flow tries to import these files content as is – but webpack is configured to load them es ES modules
I have no idea how to fix that – may be you have any thoughts?

Hi, I have the same problem... Could you fix this ?

@q2870030
Copy link

@zaytsev-mxm, @Nachosss

I am facing the same issue (no error is import scss files, but errors occurs inside the actual scss file). Could you please share the solution if you found one? Thanks.

@rofrol
Copy link

rofrol commented Jul 28, 2019

@q2870030

try this #338 (comment)

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

No branches or pull requests