Doesn't appear to work in an ESM browser environment
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, wasm
Research direction
Start by tracing read-wasm.js and wasm.js from SourceMapConsumer.initialize and SourceMapConsumer.with, using the reported browser stack to inspect where __dirname is referenced. Verify the ESM browser path can initialize lib/mappings.wasm and complete originalPositionFor without the type error or ReferenceError.
Written by the indexing model from the issue text.
Description
I'm trying to use this library for the first time, and it doesn't appear to work in a browser correctly (in an ESM webapp). My init code is very simple and taken from the docs:
import { SourceMapConsumer } from 'source-map';
SourceMapConsumer.initialize({
'lib/mappings.wasm': 'https://unpkg.com/source-map@0.7.3/lib/mappings.wasm',
});
But this has a type error:
Then I'm trying to apply a source map, basically like this:
await SourceMapConsumer.with(result.contents, null, (consumer) => {
positions.forEach((position) => {
console.log(consumer.originalPositionFor(position));
});
});
And I'm getting this in the browser console:
Uncaught (in promise) ReferenceError: __dirname is not defined
at read-wasm.js:34:34
at new Promise (<anonymous>)
at readWasm (read-wasm.js:33:12)
at wasm (wasm.js:25:16)
at source-map-consumer.js:247:14
at async _SourceMapConsumer.with (source-map-consumer.js:68:22)
at async Object.handleAddFiles [as onAddFiles] (App.tsx?t=1692066785254:100:9)
Looking at the code, I can see that this library thinks it's running in a Node environment, but it's clearly not, so maybe the environment detection code is not right?
- Dominant language
- JavaScript
- Stars
- 3.7k
- Forks
- 370
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mozilla/source-map
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
mozilla/source-map#530 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
mozilla/source-map#527 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
mozilla/source-map#524 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
mozilla/source-map#516 ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
mozilla/source-map#510 · 1 reaction ·
All issues in mozilla/source-map
Similar issues
-
bot:ai-assisted component:compact-js status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
midnightntwrk/midnight-sdk#403 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
DavidAnson/markdownlint-cli2#940 ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
githubnext/gh-aw-workshop#3692 ·
-
agent/guide documentation hive/hosted-available-lke648397-260827-5n31
Difficulty 2/5 1-3 hours Newbie friendliness 90/100