Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Browser builds with node polyfills does not work with .mjs files #427

Open
ganemone opened this issue Jul 11, 2018 · 4 comments
Open

Browser builds with node polyfills does not work with .mjs files #427

ganemone opened this issue Jul 11, 2018 · 4 comments
Labels

Comments

@ganemone
Copy link
Contributor

Browser builds with node polyfills does not work with .mjs files

Type of issue

Bug

Description

If a browser file has an .mjs extension and uses a node builtin (e.g. process), and the project has the process polyfill configured, the compiled code will reference require rather than __webpack_require__. This causes an uncaught exception in the browser since require is not defined.

NOTE: There are likely many other issues with .mjs files. We should take verify that other aspects of the build process work with .mjs files.

Current behavior

Generates code using require:

/* WEBPACK VAR INJECTION */}.call(this, require("./../../node_modules/node-libs-browser/mock/process.js")))

Expected behavior

Should generate code using webpack_require:

/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../node_modules/node-libs-browser/mock/process.js */ "./node_modules/node-libs-browser/mock/process.js")))

Steps to reproduce

  1. Scaffold a fusion project
  2. Update the package.json to have:
{
  "node":  {
    "process": true,
    "Buffer": true
  }
}
  1. Add a file: test.mjs with the following contents
export default function test() {
  console.log(process)
}
  1. import and use the test function in src/main.js
import test from './test.mjs';
test();
  1. run fusion dev
@ganemone ganemone added the bug label Jul 11, 2018
@rtsao
Copy link
Member

rtsao commented Jul 11, 2018

Looks like webpack/webpack#7032

@dmaevac
Copy link

dmaevac commented Sep 4, 2018

I see this issue too when trying to use graphql from react-apollo

Example:

import { graphql } from 'react-apollo'
graphql()

causes

Uncaught ReferenceError: process is not defined

@KevinGrandon
Copy link
Contributor

I see this issue too when trying to use graphql from react-apollo

We're going to work on this soon. What version of graphql are you using? I think that particular issue should be resolved in [email protected].

@dmaevac
Copy link

dmaevac commented Sep 4, 2018

@KevinGrandon you a re quite right, adding a resolution to my package.json for 14.0.0 resolved the issue for now.

"resolutions": { "graphql": "14.0.0" }

I was using the version specified by react-apollo which I believe is ^0.13.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants