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
Fix Metro source maps #1
Conversation
edit: |
Despite this, the source maps in Expo Go following the runtime error are still showing up in index.js. I think I will see next if Metro produces a js and sourcemaps file somewhere so I can check whether or not the |
I will next dig deeper to see if Babel is producing correct source maps or not, and if it is I’ll check where Metro might be throwing them away. |
|
I inspected the call of babel-core’s // BABEL’S RESULT:
{
metadata: {},
options: {
comments: false,
compact: true,
assumptions: {},
inputSourceMap: true, // <-- RELEVANT OPTION
caller: { name: 'metro', bundler: 'metro', platform: 'ios' },
ast: true,
babelrc: false,
code: false,
highlightCode: true,
filename: '/Users/shaun/code/matrixops/cljs-expo/expo/target/index.js',
sourceType: 'module',
sourceMaps: true, // <-- RELEVANT OPTION
targets: {},
cloneInputAst: true,
configFile: false,
browserslistConfigFile: false,
passPerPreset: false,
envName: 'production',
cwd: '/Users/shaun/code/matrixops/cljs-expo/expo',
root: '/Users/shaun/code/matrixops/cljs-expo/expo',
rootMode: 'root',
plugins: [
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin], [Plugin],
[Plugin], [Plugin], [Plugin]
],
presets: [],
parserOpts: {
sourceType: 'module',
sourceFileName: '/Users/shaun/code/matrixops/cljs-expo/expo/target/index.js',
plugins: [Array]
},
generatorOpts: {
filename: '/Users/shaun/code/matrixops/cljs-expo/expo/target/index.js',
auxiliaryCommentBefore: undefined,
auxiliaryCommentAfter: undefined,
retainLines: undefined,
comments: false,
shouldPrintComment: undefined,
compact: true,
minified: undefined,
sourceMaps: true,
sourceRoot: undefined,
sourceFileName: 'index.js'
}
},
ast: {
type: 'File',
start: 0,
end: 113946,
loc: {
start: [Object],
end: [Object],
filename: undefined,
identifierName: undefined
},
errors: [],
program: {
type: 'Program',
start: 0,
end: 113946,
loc: [Object],
sourceType: 'script',
interpreter: null,
body: [Array],
directives: [],
leadingComments: undefined,
innerComments: undefined,
trailingComments: undefined
},
comments: [ [Object], [Object] ],
leadingComments: undefined,
innerComments: undefined,
trailingComments: undefined
},
code: null,
map: null, // <-- SOURCE MAPS NOT BEING PRODUCED
sourceType: 'script',
externalDependencies: Set(0) {}
}
|
2b6ee39
to
c0d744e
Compare
The |
The Trace-Mapping library is breaking on our source map because it is expecting keys at root that shadow-cljs places at https://github.com/jridgewell/trace-mapping/blob/main/src/trace-mapping.ts#L163 const { version, file, names, sourceRoot, sources, sourcesContent } = parsed; Inspecting: > Object.keys(parsed)
[ 'version', 'file', 'sections', 'sourceRoot' ] // <-- keys missing
> Object.keys(parsed.sections[0].map)
[ 'version',
'file',
'lineCount',
'mappings',
'sources',
'sourcesContent',
'names' ] In SummaryWe have two problems so far:
|
I fixed I shared a huge progress report on what I’ve tried on the Metro issue, hoping to inspire some grace from the maintainers. |
No feedback from the Metro team yet. I think the easiest way forward is:
Here is what the source map produced by Metro looks like: {
"version": 3,
"sources": [
"__prelude__",
"/Users/shaun/code/matrixops/cljs-expo/expo/node_modules/metro-runtime/src/polyfills/require.js",
// *** OUR CLOJURESCRIPT BUILD ***
"/Users/shaun/code/matrixops/cljs-expo/expo/target/index.js",
// *** A million expo and react-native dependencies ***
"/Users/shaun/code/matrixops/cljs-expo/expo/node_modules/expo/build/Expo.js",
"/Users/shaun/code/matrixops/cljs-expo/expo/node_modules/@babel/runtime/helpers/interopRequireDefault.js",
"/Users/shaun/code/matrixops/cljs-expo/expo/node_modules/expo/build/Expo.fx.js",
"/Users/shaun/code/matrixops/cljs-expo/expo/node_modules/@babel/runtime/helpers/defineProperty.js",
"/Users/shaun/code/matrixops/cljs-expo/expo/node_modules/expo/build/environment/validate.fx.js",
// …
} And here’s my notes on the Source Map file format: Source Map file format
A source map is either basic: // parsed by BasicSourceMapConsumer
{
"version" : 3,
"file": "out.js",
"sourceRoot": "",
"sources": ["foo.js", "bar.js"],
"sourcesContent": [null, null],
"names": ["src", "maps", "are", "fun"],
"mappings": "A,AAAB;;ABCDE;"
} or indexed: // parsed by IndexedSourceMapConsumer
{
"version" : 3,
"file": "app.js",
"sections": [
{
"offset": {"line":0, "column":0},
"url": "url_for_part1.map"
},
{
"offset": {"line":100, "column":10},
"map": { // an embedded complete source map object
"version" : 3,
"file": "section.js",
"sources": ["foo.js", "bar.js"],
"names": ["src", "maps", "are", "fun"],
"mappings": "AAAA,E;;ABCDE;"
}
}
]
} Where the
Specifically, the characters in a mapping string mean the following:
|
This is awesome. Sounds like a good plan to me. Once we get it working on the example project, I think we'll want to package it up in a way that any clojurescript project can use it, and then I'll test it out in my big expo project. |
I wrote a remap.js script to fix metro source maps against a I tried to test source maps with |
https://docs.expo.dev/get-started/errors/#redbox-errors-and-stack-traces edit: thomas heller said that the |
Source map workarounds I found on
|
CLJS source maps are not being used by Expo, which makes runtime errors difficult to diagnose.
Currently, this PR is for discovering where the source maps are being lost— Expo, Metro, or Babel.
I currently believe this is a Metro issue, not a Babel issue:
See facebook/metro#104 (comment)
My current understanding is that Expo uses Metro uses Babel, and that Expo’s babel.config.js file can be used to override the Babel options used ultimately by Metro. This is hard to verify.
According to Babel’s (config page](https://babeljs.io/docs/en/configuration#babelconfigjson), all Babel options are allowed in the config here, so I’m trying to add
inputSourceMap: true
.I’m throwing in an error inside our main component to test the source map, but still getting back a JS stack trace (see screenshot above).
Seeking Help
The Expo discord channel and Metro contributors on GitHub have been silent so far. But a Babel maintainer has said this is not their issue, since babel-core works with
inputSourceMap
.