An open API service indexing awesome lists of open source software.

https://github.com/tmpfs/swc-builtin-shim

MVP for an attempt to shim built in modules using spack
https://github.com/tmpfs/swc-builtin-shim

Last synced: 4 months ago
JSON representation

MVP for an attempt to shim built in modules using spack

Awesome Lists containing this project

README

        

# Spack Builtin Shim

An attempt to use shims for node builtin modules.

```
yarn install
npx spack
```

When compiling with `spack` for the browser and using builtin modules such as `assert` and `events` we encountered this error when executing the generated bundle:

```
Uncaught SyntaxError: Cannot use import statement outside a module
```

It appears that builtin modules are passed through as `import` statements untouched as there is no available code to compile.

However, when we added the `assert` and `events` packages to be used as shims and updated `.swcrc` to configure the `paths`:

```json
{
"jsc": {
"paths": {
"assert": ["node_modules/assert"],
"events": ["node_modules/events"]
}
}
}
```

These shims for the builtin modules are not used and the compiled bundle still includes the original import statements.

* [List of builtin shims](https://github.com/browserify/browserify#compatibility)