webpack-contrib/script-loader

Not working with react-hot loader

Closed this issue ยท 7 comments

require("script!./file.js");

Result in file.js:

Uncaught ReferenceError: module is not defined

File.js content after react-hot loader transformation:

/* REACT HOT LOADER */ if (module.hot) { (function () { var ReactHotAPI = require("D:\\Dev\\git\\React\\react-admin-example\\node_modules\\react-hot-loader\\node_modules\\react-hot-api\\modules\\index.js"), RootInstanceProvider = require("D:\\Dev\\git\\React\\react-admin-example\\node_modules\\react-hot-loader\\RootInstanceProvider.js"), ReactMount = require("react/lib/ReactMount"), React = require("react"); module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(function () { return RootInstanceProvider.getRootInstances(ReactMount); }, React); })(); } (function () {

// FILE CONTENT

/* REACT HOT LOADER */ }).call(this); if (module.hot) { (function () { module.hot.dispose(function (data) { data.makeHot = module.makeHot; }); if (module.exports && module.makeHot) { var makeExportsHot = require("D:\\Dev\\git\\React\\react-admin-example\\node_modules\\react-hot-loader\\makeExportsHot.js"), foundReactClasses = false; if (makeExportsHot(module, require("react"))) { foundReactClasses = true; } var shouldAcceptModule = true && foundReactClasses; if (shouldAcceptModule) { module.hot.accept(function (err) { if (err) { console.error("Cannot not apply hot update to " + "file.js" + ": " + err.message); } }); } } })(); }

// SCRIPT-LOADER FOOTER

Than don't use both on the same file.

๐Ÿ˜ž

Can you please give more details on how to resolve this problem? I am having the same issue, and I'm not following how to implement the suggested solution. I'm new to webpack.

sokra commented

require("!script!./file.js"); should solve it... note the leading ! in the request.

Thanks, that worked.

I was coming across a require not defined error and adding the ! at the beginning like @sokra suggested fixed the issue for me.

h0gar commented

This solved an issue for me but I don't understand. What is the leading ! doing exactly?