Coder Social home page Coder Social logo

Comments (18)

amangeot avatar amangeot commented on September 24, 2024 2

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.

StevenLangbroek avatar StevenLangbroek commented on September 24, 2024 1

(I'm investigating clearing the require cache after compile as an alternative solution)

from webpack-hot-server-middleware.

masad-frost avatar masad-frost commented on September 24, 2024

As you can see in the start script. I have to run npm run build before npm run serve

from webpack-hot-server-middleware.

richardscarrott avatar richardscarrott commented on September 24, 2024

@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.

masad-frost avatar masad-frost commented on September 24, 2024

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.

masad-frost avatar masad-frost commented on September 24, 2024

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.

skyuplam avatar skyuplam commented on September 24, 2024

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.

vovkasm avatar vovkasm commented on September 24, 2024

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.

clempat avatar clempat commented on September 24, 2024

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.

vovkasm avatar vovkasm commented on September 24, 2024

@clempat Yes, of course! Node will not reload files that required with same name... it cache all requires.

from webpack-hot-server-middleware.

StevenLangbroek avatar StevenLangbroek commented on September 24, 2024

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.

StevenLangbroek avatar StevenLangbroek commented on September 24, 2024

Alright, so I fixed the issue, but it's a rather brute-force approach:

  • Add [hash] to output.filename for server, put them in an easily cleanable folder
  • When creating multicompiler, find by name: server
  • Hook into beforeCompile and rimraf the whole folder built to

2 questions:

  1. Can anybody think of any unintended side-effects?
  2. Can we incorporate this into this package? If not, I'd gladly contribute docs.

from webpack-hot-server-middleware.

vovkasm avatar vovkasm commented on September 24, 2024

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.

StevenLangbroek avatar StevenLangbroek commented on September 24, 2024

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.

StevenLangbroek avatar StevenLangbroek commented on September 24, 2024

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.

StevenLangbroek avatar StevenLangbroek commented on September 24, 2024

@vovkasm Should we try to involve someone from webpack core to figure out the right way to do this?

from webpack-hot-server-middleware.

StevenLangbroek avatar StevenLangbroek commented on September 24, 2024

Any word on this @vovkasm? I'd love to help but am unsure how to continue...

from webpack-hot-server-middleware.

komlevv avatar komlevv commented on September 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.