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: TypeError: files.forEach is not a function #18

Closed
IAMtheIAM opened this issue Nov 27, 2017 · 11 comments
Closed

Module build failed: TypeError: files.forEach is not a function #18

IAMtheIAM opened this issue Nov 27, 2017 · 11 comments

Comments

@IAMtheIAM
Copy link
Contributor

IAMtheIAM commented Nov 27, 2017

After updating 2.2.0 to 3.0.0:

Module build failed: TypeError: files.forEach is not a function
    at exports.default (C:\Source\node_modules\@epegzz\sass-vars-loader\dist\utils\watchFilesForChanges.js:6:9)
    at Object.exports.default (C:\node_modules\@epegzz\sass-vars-loader\dist\sassVarsLoader.js:13:38)

The file exists, but webpack cannot resolve it. Is there a breaking change?

@epegzz
Copy link
Owner

epegzz commented Nov 28, 2017

What node version are you running on? The latest sass-vars-loader requires node v4.8.6? Hope that's not an issue. I could lower the requirement with Babel but I thought Node v4.8.6 is a reasonable target nowadays.

@IAMtheIAM
Copy link
Contributor Author

I am running 6.10.0. Npm 5.5.1

I will check my config again and update you with what i find,.

@epegzz
Copy link
Owner

epegzz commented Nov 29, 2017

Second guess would be, that you specified files in the config, but it's not an Array :)

@epegzz
Copy link
Owner

epegzz commented Dec 13, 2017

Closing this issue, feel free to re-open if the issue still exists.

@epegzz epegzz closed this as completed Dec 13, 2017
@IAMtheIAM
Copy link
Contributor Author

IAMtheIAM commented Dec 15, 2017

The issue just resurfaced.

const sassVarsConfig = querystring.stringify({
   vars : JSON.stringify({
      // susyIsDevServer: susyIsDevServer,
      // env            : METADATA.ENV
      // fullHost: METADATA.fullHost
   }), // Or use 'files" object to specify vars in an external .js or .json file
   files: [path.resolve(Helpers.paths.appRoot + '/assets/styles/sass-js-variables.js')]
});

That is my config. It is an array. What else might cause this?

Module build failed: TypeError: files.forEach is not a function
    at exports.default (C:\Source\frontend\node_modules\@epegzz\sass-vars-loader\dist\utils\watchFilesForChanges.js:6:9)
    at Object.exports.default (C:\Source\frontend\node_modules\@epegzz\sass-vars-loader\dist\sassVarsLoader.js:14:38)
 @ ./src/app-components/app/app.style.scss 4:14-526
 @ ./src/app-components/app/app.component.ts
 @ ./src/app-components/app/app.spec.ts
 @ ./src \.spec\.ts
 @ ./config/karma.entry.js

I'm using Node v8.9.3 now

@epegzz
Copy link
Owner

epegzz commented Dec 16, 2017

Okay, don't use JSON.stringify :) The vars parameter must be a JS object, not a string.

@epegzz epegzz reopened this Dec 16, 2017
@epegzz
Copy link
Owner

epegzz commented Dec 16, 2017

If the issue should still persist even without the JSON.stringify, then try a console.log(path.resolve(Helpers.paths.appRoot + '/assets/styles/sass-js-variables.js')), then paste the output of the log in a terminal with an ls command like this: ls /the/result/of/console_log and see if the file actually exisis

@IAMtheIAM
Copy link
Contributor Author

I ran the command and the file does exist. I also removed the JSON.stringify and still files.foreach is not a function.

@IAMtheIAM
Copy link
Contributor Author

IAMtheIAM commented Dec 18, 2017

I fixed it. I was using querystring.stringify and then in module.rules i used

{
          @epegzz/sass-vars-loader?' + sassVarsConfig`
}

This worked in 2.x, but in 3.x it failed. I removed querystring.stringify (and JSON.stringify) and switched to


const sassVarsConfig = {
   syntax: 'scss',
   files: [path.resolve(Helpers.paths.appRoot + '/assets/styles/sass-js-variables.js')]
   ,vars : {
      // susyIsDevServer: susyIsDevServer,
      // env            : METADATA.ENV
      // fullHost: METADATA.fullHost
   } // Or use 'files" object to specify vars in an external .js or .json file
};

// in module.rules
 {
          loader : '@epegzz/sass-vars-loader',
          options: sassVarsConfig
  }

and it works. Thanks for the tip!

@epegzz
Copy link
Owner

epegzz commented Dec 19, 2017

Hm right. I wonder if the lib should actually support query string parameters. 🤔

@IAMtheIAM
Copy link
Contributor Author

It would be good as a fallback support, some people still use that. But load options is the new standard. Maybe it could just throw an error if query string is given, otherwise I don't think it is too hard to parse query string params right?

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

2 participants