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

Module build failed: Error: Something wrong with provided resources. Make sure 'options.resources' is String or Array of Strings. #38

Closed
IAMtheIAM opened this issue Jul 7, 2017 · 13 comments · Fixed by #134

Comments

@IAMtheIAM
Copy link

IAMtheIAM commented Jul 7, 2017

The plugin throws error with webpack 3.1.0

                  {
                     loader: 'sass-resources-loader',
                     options: {
                        resources: ['./src/assets/styles/variables.scss', './src/assets/styles/mixins.scss'],
                     }
                  },

Module build failed: Error: 
      Something wrong with provided resources.
      Make sure 'options.resources' is String or Array of Strings.

Upon debugging webpack, it appears sass-resources-loader\lib\utils\parseResources.js line 34 is returning blank. Glob.sync is not returning the absolute path. So in sass-resources-loader\lib\loader.js line 54, var resourcesLocations is set to empty

@Maushundb
Copy link

Getting the same with Webpack 2.6

@IAMtheIAM
Copy link
Author

More at this issue 40

@alex35mil
Copy link
Member

I believe this can be closed. 1.3.1 and few notes added in f3d2cf6 should resolve these issues.

@aFcFzF
Copy link

aFcFzF commented Sep 7, 2018

resources: ['./src/assets/styles/variables.scss', './src/assets/styles/mixins.scss'],

the path in options.resources must be a absolute path, eg:
resources: [path.resolve(__dirname, './src/assets/styles/variables.scss')]

path.resolve is needed,good lucky!

@pangz1
Copy link

pangz1 commented Jan 31, 2020

resources: ['./src/assets/styles/variables.scss', './src/assets/styles/mixins.scss'],

the path in options.resources must be a absolute path, eg:
resources: [path.resolve(__dirname, './src/assets/styles/variables.scss')]

path.resolve is needed,good lucky!

using absolute path still get the error

@justin808
Copy link
Member

@pangz1 any chance that you can dig into this. If a PR is needed, I'll review.

@dkaraush
Copy link

This error can be misleading. It says that the resources array is empty in config, but really there can be just zero files resolved by glob.
I spent half an hour, added logs into parseResources.js and only after I realized that I used wrong config with wrong pathes. 🤦‍♂️

@justin808
Copy link
Member

@dkaraush @Tomburgs any thoughts if we could have a PR that could give a better error message?

@dkaraush
Copy link

dkaraush commented Dec 29, 2020

Ok, I think this error should be turned into warning, and before it there should be another check.
The thing is, if there are no resource files found by glob (for example, I setup as globalStyles/*.scss, but haven't put any files there yet), then the webpack will just fail to build. In my opinion it can be only little warning, that there is just extra rule in webpack config. (!resourcesLocations.length returns true if it is an empty array)
I'm not very familiar with webpack philosophy, maybe that's ok, actually.
And another check can be extended even before putting those resources into glob.

I made a PR of my thoughts, feel free to add any comments and change it.

@Tomburgs
Copy link
Member

@dkaraush I think your solution might bring more confusion, although I do agree that this should be a non-fatal error.
I was thinking perhaps in utils/parseResources under the isArrayOfStrings statement we could check if any of the paths didn't resolve any files and, if so, display a warning message?

Something like so:

if (isArrayOfStrings(locations)) {
    logger.debug('options.resources is Array of Strings:', true);

    return locations.reduce((resolvedFiles, directory) => {
        const files = glob.sync(directory);

        if (files.length === 0) {
            logger.warn(`
                Couldn't find any files under the ${directory} directory.
                Did you forget to resolve this to an absolute path with path.resolve?
            `);
        }

        return [...resolvedFiles, ...files];
    }, []);
}

Let me know what you think @justin808 & @dkaraush.

@dkaraush
Copy link

Yes, I agree with you, that would be much more clear. But keep in mind that single string can also bring an empty array of files.
You can make those changes in my PR or make your own and abandon mine. I don't like how testing of console.log works there, but didn't find any better solution.

@justin808
Copy link
Member

I like what @Tomburgs said, but I think the error should be fatal, as warnings might be ignored.

@Tomburgs
Copy link
Member

Done. Have a look at #134 @justin808 & @dkaraush!

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

Successfully merging a pull request may close this issue.

8 participants