Comments (18)
I think I get a similar error when I import my files dynamically
It works fine with a static import:
import ExploreView from './containers/ExploreView'
but with a dynamic import:
import Loadable from 'react-loadable'
export const ExploreView = Loadable({
loader: () => import(/* webpackChunkName: "explore" */ './containers/ExploreView'),
loading: () => null,
})
Error: Cannot find module './2.serverRenderer.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Function.requireEnsure [as e] (C:\Users\Adrien\Documents\Dev\front-end-ssr\dist\server\webpack:\webpack\bootstrap 134319b5727946bc9a01:39:1)
at loader (C:\Users\Adrien\Documents\Dev\front-end-ssr\dist\server\webpack:\src\universal\routes\explore\index.js:9:17)
at C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:28:12
at capture (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:21:17)
at load (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:27:18)
at new LoadableComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:149:15)
at C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:294:18
at measureLifeCyclePerf (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:75:12)
at ReactCompositeComponentWrapper._constructComponentWithoutOwner (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:293:16)
at ReactCompositeComponentWrapper._constructComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:279:21)
at ReactCompositeComponentWrapper.mountComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:187:21)
at Object.mountComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactReconciler.js:45:35)
from webpack-hot-server-middleware.
(I'm investigating clearing the require cache after compile as an alternative solution)
from webpack-hot-server-middleware.
As you can see in the start script. I have to run npm run build
before npm run serve
from webpack-hot-server-middleware.
@masad-frost that link doesn't seem to work... I tried out the master branch however and can't reproduce that error, even when removing npm run build -- --env.server
from npm run start
... have you worked around the problem?
from webpack-hot-server-middleware.
Weird, I'm still getting the same error, even made sure I reinstalled my node_modules.
I think maybe you didn't delete the dist
folder after you removed npm run build -- --env.server
?
Honestly prebuilding doesn't bother me that much, but I just finding intriguing and a bit worried there might be an underlying problem.
It could also be an Angular issue, where it doesn't properly resolve modules in memory files. Here's a pastebin when going to localhost:3000/lazy
.
from webpack-hot-server-middleware.
Seems like I found a solution for my problem but it only works for my Angular chunks. If I use module-map-ngfactory-loader
it should solve my problem. That module resolves dynamically imported modules before starting the Angular server.
I'm not sure what you can do about import()
and similar functions (i.e. react-loadable), but I'm sure there's a way to resolve them early if this becomes an issue. Maybe something likes this
let module;
if (process.BROWSER) {
module = import('path-to-module');
} else {
module = require('module');
}
from webpack-hot-server-middleware.
I found the same error in smooth-code/loadable-components. Appearently it doesn't work with code splitting.
gregberge/loadable-components#74
from webpack-hot-server-middleware.
Same problem. Root cause is that this module evaluated only entry from webpack's memory-fs. And evaluated code contains require('chunk-module-name')
, but there is not such file, because it is exists only in webpack's memory-fs.
I plan to do some experiments with hook-in node require
subsystem to allow loading from memory-fs, but not immediately, because of lack of free time now.
Fast hack seems to enable writing files on disk, something like:
app.use(devMiddleware(multiCompiler, { publicPath, serverSideRender: true, writeToDisk: true })) // <-- here
app.use(hotMiddleware(clientCompiler))
app.use(hotServerMiddleware(multiCompiler, { serverRendererOptions: { outputPath } }))
from webpack-hot-server-middleware.
On our side we were using write-file-webpack-plugin
. Which make this error disappear probably the same way as the solution above BUT now node does not refresh the bundles. I see the changes done in my output directory but not on the express response. @vovkasm are you getting the same issue ?
from webpack-hot-server-middleware.
@clempat Yes, of course! Node will not reload files that required with same name... it cache all requires.
from webpack-hot-server-middleware.
Hey @vovkasm, colleague of @clempat here :). We tumbled down this rabbit-hole together. We found a working solution (we had a suspicion the require cache was the issue), adding a [hash]
substitution to the output.filename
, but that leaves us with another issue: massive build-up of amount of files on disk. Do you have any thoughts on how to automate clean-up in the hot-server middleware? Something like "hang on to old stats object, on compile clean-up references in there before propagating changes"?
from webpack-hot-server-middleware.
Alright, so I fixed the issue, but it's a rather brute-force approach:
- Add
[hash]
tooutput.filename
forserver
, put them in an easily cleanable folder - When creating multicompiler, find by
name: server
- Hook into
beforeCompile
andrimraf
the whole folder built to
2 questions:
- Can anybody think of any unintended side-effects?
- Can we incorporate this into this package? If not, I'd gladly contribute docs.
from webpack-hot-server-middleware.
One note only. Clearing all files may be dangerous (depending on configuration), because other tools can generate files in the same folder.
I still think that proper way to handle this will be to inject custom require hook that can require files from memory-fs.
from webpack-hot-server-middleware.
I'm not even sure what's causing the issue tbh. It's not the require cache, as you're using require-from-string
...
from webpack-hot-server-middleware.
I still think that proper way to handle this will be to inject custom require hook that can require files from memory-fs.
Yeah I definitely agree with this. Writing to file isn't exactly the way to go...
because other tools can generate files in the same folder.
The nice thing is that if it uses webpack, it'll be put back in place after a successful compile...
from webpack-hot-server-middleware.
@vovkasm Should we try to involve someone from webpack core to figure out the right way to do this?
from webpack-hot-server-middleware.
Any word on this @vovkasm? I'd love to help but am unsure how to continue...
from webpack-hot-server-middleware.
@masad-frost @richardscarrott this issue should probably stay open.
Getting same Error: Cannot find module '..'
when using React.lazy(()=> import (...))
@vovkasm were you able to solve this?
from webpack-hot-server-middleware.
Related Issues (20)
- Side effect from require server render from string
- listen EADDRINUSE: address already in use :::8080 HOT 2
- please remove `yarn` from dependencies HOT 4
- TypeError: serverRenderer is not a function
- Hangs when errors are thrown inside server bundle HOT 1
- filtering websocket webpack-hot-reloading calls from react-hot-server-middleware HOT 1
- serverRenderer is not a function HOT 10
- serverRenderer is not a function HOT 1
- My entry chunk is renamed to an async chunk HOT 2
- is it possible to call the default route from another route in express HOT 5
- serverRender is not a function
- use webpack-hot-server-middleware with typescript HOT 2
- Another "serverRenderer is not a function" question. HOT 4
- React Redux store not found in context HOT 4
- cannot find module 'react'
- Why is yarn in runtime dependencies? HOT 1
- Separating Routes? HOT 6
- Error is thrown when the example is run.
- Error when compiling when using Hapijs HOT 1
- bug flow type HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack-hot-server-middleware.