Skip to content

webpack alias does not work in develop mode... #4089

Closed
@busticated

Description

@busticated

i'm trying to use a module which presents the same API across browser and server / node.js contexts but uses different implementations for each and i'm hitting a weird issue.

i have a dependency that uses the browser field in package.json (info: https://github.com/defunctzombie/package-browser-field-spec) - when running gatsby build (or develop) it appears this setting is ignored (perhaps a webpack v1 issue).

when i manually add a webpack alias via gatbsy's modifyWebpackConfig API, gatsby build works as expected but develop fails w/ Error: WebpackError while compiling html.js

here's modifyWebpackConfig in my gatsby-node.js file:

exports.modifyWebpackConfig = ({ config, stage }) => {
    config.merge({
        resolve: {
            alias: {
                '@foo/bar': '@foo/baz/index.js'
            }
        }
    });

    return config;
};

my issue seems similar to: #1654 but there's no obvious solution there.

the full error shown during `develop`

error There was an error compiling the html.js component for the development server.

See our docs page on debugging HTML builds for help https://goo.gl/yL9lND


  Error: WebpackError
  
  - option-manager.js:180 
    [my-site]/[babel-core]/lib/transformation/file/options/option-manager.js:180:17
  
  - Array.map
  
  - option-manager.js:158 Function.normalisePlugins
    [my-site]/[babel-core]/lib/transformation/file/options/option-manager.js:158:20
  
  - option-manager.js:234 OptionManager.mergeOptions
    [my-site]/[babel-core]/lib/transformation/file/options/option-manager.js:234:36
  
  - option-manager.js:368 OptionManager.init
    [my-site]/[babel-core]/lib/transformation/file/options/option-manager.js:368:12
  
  - index.js:212 File.initOptions
    [my-site]/[babel-core]/lib/transformation/file/index.js:212:65
  
  - index.js:135 new File
    [my-site]/[babel-core]/lib/transformation/file/index.js:135:24
  
  - pipeline.js:46 Pipeline.transform
    [my-site]/[babel-core]/lib/transformation/pipeline.js:46:16
  
  - index.js:46 transpile
    [my-site]/[babel-loader]/lib/index.js:46:20
  
  - fs-cache.js:79 
    [my-site]/[babel-loader]/lib/fs-cache.js:79:18
  
  - fs-cache.js:15 ReadFileContext.callback
    [my-site]/[babel-loader]/lib/fs-cache.js:15:14
  
  - From previous event:
  
  - develop-html.js:40 _callee$
    [my-site]/[gatsby]/dist/commands/develop-html.js:40:46
  
  - next_tick.js:131 _combinedTickCallback
    internal/process/next_tick.js:131:7
  
  - next_tick.js:180 process._tickCallback
    internal/process/next_tick.js:180:9

Environment

Gatsby version: v1.9.175
Node.js version: v8.9.4
Operating System: v10.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions