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

setting mimeTypes option falls with error #346

Closed
webmasterslava opened this issue Nov 11, 2018 · 8 comments
Closed

setting mimeTypes option falls with error #346

webmasterslava opened this issue Nov 11, 2018 · 8 comments

Comments

@webmasterslava
Copy link

webmasterslava commented Nov 11, 2018

setting mimeTypes option falls with error:

Error: Attempt to change mapping for "php" extension from "application/x-httpd-php" to "text/html". Pass `force=true` to allow this, otherwise remove "php" from the list of extensions for "text/html".

In webpack-dev-middleware/index.js file replace line

mime.define(options.mimeTypes);
by
mime.define(options.mimeTypes, true);

@evenstensberg
Copy link
Member

Isn't this something you could change in your php.ini/.htaccess? This would only supress the warning, but warnings are nice for different scenarios.

Could you provide a better elaboration of what you are trying to accomplish? Is it loading a php file? If so, then this should be sufficient as long as your proxy is defined correctly.

@webmasterslava
Copy link
Author

  1. It's not a warning, it's error that doesn't allow to run node.js app that uses webpack-dev-middleware.
  2. it's not related with php, php is just an example, I can use any other mime type that is already exists in the default list of mime types, and it will fall with error when I start node.js app.

@gpoitch
Copy link
Member

gpoitch commented Dec 11, 2018

Just hit this issue. I believe it happens when you have multiple webpack configs (e.g. client & server) so mime.define gets called twice with the same thing and that module throws the error.

"By default this method will throw an error if you try to map a type to an extension that is already assigned to another type. Passing true for the force argument will suppress this behavior (overriding any previous mapping)."
https://github.com/broofa/node-mime#mimedefinetypemap-force--false

@alexander-akait
Copy link
Member

@gpoitch thanks for answer, can you send this to README?

@gpoitch
Copy link
Member

gpoitch commented Dec 12, 2018

@evilebottnawi Still need to figure out the best solution.

  1. Update the code here with the force flag as @webmasterslava suggests mime.define(options.mimeTypes, true)
  2. Expose an option to set the flag
  3. Tell people to add their own code to manage only setting it once
  4. PR to node-mime so it doesn't throw when defining a mime to the same thing it's already set to.

@alexander-akait
Copy link
Member

@gpoitch i think 2 solution is better, in some cases it is normal throw error, but we allow for other force define.

@gpoitch
Copy link
Member

gpoitch commented Dec 12, 2018

#349

@alexander-akait
Copy link
Member

Fixed #349

@webmasterslava Answer here #346 (comment) and you can use force to redefine mime types

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

4 participants