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

Get exported function from server's entry file #60

Open
ilyaagarkov opened this issue May 26, 2018 · 3 comments
Open

Get exported function from server's entry file #60

ilyaagarkov opened this issue May 26, 2018 · 3 comments

Comments

@ilyaagarkov
Copy link

Hi!

I have a misunderstanding about how I can export render functions from a server file
I get empty object from res.locals.isomorphic.exports

config for server

const server = {
  mode: 'development',
  entry:'./src/server.js',
  output: {
    path: '/',
    publicPath: 'http://localhost:3000/scripts/',
    filename: `server.bundle.js`,
  },
  module: {
    rules: [js]
  },

}

server.js

export const fun =() => console.log('!!!!!!')

export default {
  foo: () => {}
}
@satazor
Copy link
Contributor

satazor commented Jul 26, 2018

@ilyaagarkov I've never tried using a default export actually. Could you instead export a render function to see if it's available?

(sorry or the late response)

@arthens
Copy link

arthens commented Oct 13, 2018

I ran into the same problem, and after spending a few hours on it I managed to get it works. In my case the problem was that webpack-isomorphic-dev-middleware uses require-from-string to extract exports from the server bundle. However, this only works is the server bundle is generated in a very specific way.

In my case I fixed by adding library and libraryTarget to output.

    output: {
            ...
            library: 'library',
            libraryTarget: 'commonjs-module',
        },

This makes it so that the server bundle has module.exports (instead of being wrapped in webpack helper functions), so that require-from-string can extract the exports.

@satazor
Copy link
Contributor

satazor commented Mar 13, 2019

@arthens Correct, I will leave this open as a reminder to make this clear in the README

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

3 participants