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
- Host: GitHub
- URL: https://github.com/tmpfs/swc-builtin-shim
- Owner: tmpfs
- Created: 2021-07-23T04:55:52.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-23T04:57:10.000Z (almost 4 years ago)
- Last Synced: 2025-01-05T02:12:15.431Z (6 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)