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

Add semicolon to source-map-support banner to fix 'require() is not a function' error #162

Merged
merged 1 commit into from
Jun 22, 2019

Conversation

nkohari
Copy link
Contributor

@nkohari nkohari commented Jun 22, 2019

I kept running into this error when executing my code that was bundled by Backpack:

/******/ (function(modules) { // webpackBootstrap
         ^
TypeError: require(...) is not a function
    at Object.<anonymous> (/Users/nkohari/Work/hireflow/packages/api/dist/bundle.js:2:10)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11

After some digging, I realized that it's a simple fix. Here's what's being generated on master:

require('.../source-map-support/register.js')
/******/ (function(modules) { // webpackBootstrap
// ...

Node interprets this as passing the webpack output into the result of require() as an argument. If we change the banner to this fixes the issue (note the semicolon):

require('.../source-map-support/register.js');
/******/ (function(modules) { // webpackBootstrap
// ...

This patch just adds that semicolon to the banner that's included at the top of the bundle. I'm not sure if there's just something strange about my Webpack config that makes this happen. However, there's no downside to adding the semicolon, so even if I've hit an edge case it seems like a good change.

@jaredpalmer jaredpalmer merged commit eb97811 into jaredpalmer:master Jun 22, 2019
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

Successfully merging this pull request may close these issues.

2 participants