-
Notifications
You must be signed in to change notification settings - Fork 49
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 not found. attempted require... #16
Comments
Does your clientside bundle require the |
This seems to happen when using prerender-loader with webpack-dev-server, I created a very simple demo, I'm trying to figure out what the complete workflow with prerender-loader should be. If the entry point exports a function that only executes at build time, how does the application run on the client? |
I know this is a real issue, but this plugin isn't designed to be used in development mode (with hot-reloading libraries): you should only need to apply it on a production build (with no added code from webpack hot-reloading libraries) |
I assumed that initially, but the readme says "works with webpack-dev-server" and the library uses Webpack's entry point by default, which was supposed to be for client code, so I was getting mixed signals. The only way how I got both prerender and client code to work is to duplicate the render call: import React from 'react'
import { render } from 'react-dom'
import App from './app'
render(<App />, document.getElementById('root'))
export default () => {
render(<App />, document.getElementById('root'))
} Is that how it's supposed to be used? I'm not confused too much about the duplicated call, I know that the contents of the exported function can be anything, for example (I'm not talking about webpack-dev-server here, let's assume that I'm only including prerender-loader in the production Webpack configuration.) Let me know if I explained the confusion well enough. |
some libraries we rely on do have some issues with How to fix it? Does if (typeof prerender === undefined){
require('some-lib')
} |
Ok for now, I am doing something like this if (!(navigator.userAgent.includes('Node.js') || navigator.userAgent.includes('jsdom'))){
// require here
} |
FWIW, I would not recommend using module.exports = function(env, argv) {
const isProd = argv.mode === 'production';
return {
plugins: [
new HtmlWebpackPlugin({
template: isProd ? '!!prerender-loader?string!index.html' : 'index.html',
})
]
};
} |
Regarding conditional escaping, you can do this: if (self.PRERENDER) {
// code is being run in prerender-loader
}
else {
// code is being run in browser
} |
This should fix #16, allowing Node builtin modules to be required when using a JS entry module.
I've added a fallback to Node require() so this should work now. |
Thanks for your heads up. I’m aware that it should not work with webpack-dev-server. I’m still struggling with multiple entries issue though, hope you can help me with it. |
@edwardfhsiao I'll take a look. |
I get an error when using prerender-loader. It seems to fail with the below error. I traced it to this line and it appears that the only keys in
compilation.assets
aressr-bundle.js
. Any suggestions?The text was updated successfully, but these errors were encountered: