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

🐛 BUG: dev server fails with "Uncaught TypeError: require$$0 is not a function" due to incorrect require() transform #3911

Open
1 task done
ncpa0cpl opened this issue Jun 25, 2022 · 0 comments

Comments

@ncpa0cpl
Copy link

Quick checklist

  • I am using the latest version of Snowpack and all plugins.

What package manager are you using?

yarn

What operating system are you using?

Linux

Describe the bug

Dev server fails with an Uncaught TypeError: require$$0 is not a function. This error occurs in a transformed file of a define-properties package.

It appears to me that this bug occurs due to incorrect transformation of that package require() call. In the package the following line:

var hasPropertyDescriptors = require('has-property-descriptors')();

is being transformed to

import * as hasPropertyDescriptors$1 from '/_snowpack/pkg/has-property-descriptors.v1.0.0.js';

function getDefaultExportFromNamespaceIfNotNamed (n) {
	return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
}

var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(hasPropertyDescriptors$1);

var hasPropertyDescriptors = require$$0();

in the original code the require() returns a function, in the transformed code however, the getDefaultExportFromNamespaceIfNotNamed()is returning the module with that function under a "default" property, leading to this error. I suspect this is because that module has more than one property and Object.keys(n).length === 1 condition returns false.

This error does occur only when using a development server.

Steps to reproduce

  1. npx create-snowpack-app
  2. install define-properties (npm i define-properties)
  3. import that package and use it
  4. start the dev server
  5. open the page in the browser
  6. it will fail with a Uncaught TypeError: require$$0 is not a function error in the console

Link to minimal reproducible example (optional)

No response

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

1 participant