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

Cannot add resolve property in webpack config #1193

Closed
Stupidism opened this issue Mar 23, 2017 · 4 comments
Closed

Cannot add resolve property in webpack config #1193

Stupidism opened this issue Mar 23, 2017 · 4 comments

Comments

@Stupidism
Copy link

Stupidism commented Mar 23, 2017

What do I want to do.

I wanted to add resolve.alias like #945 said.

  resolve: {
    alias: {
      '~': path.resolve(__dirname, '../src'),
    },
  },

But failed. Finally I found add blank resolve will cause the same problem:

resolve: {},

Current result

When I run yarn start, the error showed up in command line:

/.../webpack:/src/core/fetch/fetch.client.js:14
export const Headers = self.Headers;
^
ReferenceError: self is not defined

It seems webpack resolved fetch to fetch.client for some reason

Expected behaviour

webpack should resolve to fetch.server on the server side.

Temp way to fix

I found the temp way to fix this. I put it here in case someone has the same problem like me.
I'm not sure this is a problem with RSK or webpack. Maybe webpack/webpack#4160 is related.

const clientConfig = {
  ...config,

  name: 'client',
  target: 'web',

  resolve: {
    ...config.resolve,
    // Webpack should automatically set mainFields for `target: 'web'`
    // https://webpack.js.org/configuration/resolve/#resolve-mainfields
    // Webpack fails to do this when resolve property is specified.
    // Wait for RSK or webpack to fix this
    // https://github.com/kriasoft/react-starter-kit/issues/1193
    mainFields: ['browser', 'module', 'main'],
  },
}

const serverConfig = {
  ...config,

  name: 'server',
  target: 'node',

  resolve: {
    ...config.resolve,
    // Webpack should automatically set mainFields for `target: 'node'`
    // https://webpack.js.org/configuration/resolve/#resolve-mainfields
    // Webpack fails to do this when resolve property is specified.
    // Wait for RSK or webpack to fix this
    // https://github.com/kriasoft/react-starter-kit/issues/1193
    mainFields: ['module', 'main'],
  },
}
@Stupidism
Copy link
Author

WTF. I can't reproduce this even on the same commit. I think I should just close it myself.

@plemarquand
Copy link

@Stupidism You're not crazy, I just had this happen too. Your workaround fixed it for me. It does feel like it could be related to webpack/webpack#4160.

@Stupidism
Copy link
Author

Good to know I'm not crazy but only stupid!(LOL) @plemarquand

@lennerd
Copy link

lennerd commented Mar 31, 2017

We experienced the same. And it solved our issue when linking node modules. Thanks @Stupidism ! ❤️ Looks like a bug in webpack though.

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