Comments (18)
Source maps are working well for me now. here's what i did:
ctx = MiniRacer::Context.new
ctx.eval(my_script_string, filename: "my_script_string.js") # important!
ctx.attach('readSourceMap', proc { |source_filename| File.read("#{source_filename].map") })
now, somewhere in your js:
if (process.env.NODE_ENV === "production") {
require("source-map-support").install({
retrieveSourceMap: (filename) => {
return {
url: filename,
// @ts-ignore
map: readSourceMap(filename)
};
}
});
}
This works with a fairly advanced webpack setup flawlessly.
from mini_racer.
@ignisf tried to make that work but it was futile
from mini_racer.
from mini_racer.
-duh- okay, sorry that makes perfect sense. The require
is translated by webpack and the npm package will patch Error.prototype
(or something like that).
So technically no webpack is required and you could simply "eval" source-map-support, attach readSourceMap
and then eval your script - at least if I understand this correctly.
from mini_racer.
Hi,
Could you by any chance provide a sample app we can work off of?
Thanks :)
from mini_racer.
from mini_racer.
I wanted to try if I could do something with https://github.com/evanw/node-source-map-support/. Do you think it could be useful in this case?
from mini_racer.
@SamSaffron your comment, it seems to imply that V8 isn't going to change how it reports it's errors, and that the consumer (in this case mini_racer) would have to scan the sourcemap and construct a meaningful view of the error itself from the data returned by V8.
Is that a fair assessment?
from mini_racer.
Can you elaborate a bit what was the biggest problem when you gave https://github.com/evanw/node-source-map-support a try, @siassaj?
from mini_racer.
I just committed and deployed filename support for MiniRacer.
But... sourcemap resolution all happens after that. You have to run your backtrace through a parser, load files and resolve locations, its a tedious job.
from mini_racer.
Hi all
@tisba sorry didn't see the github notification. I will read into it soon and see what's up :)
@SamSaffron to clarify, you mean that whatever process runs miniracer should collect the error and the backtrace, then run another program/routine that uses the sourcemap and source files to figure out the correct code to show, then send it back to the original program to show the user, yes?
from mini_racer.
to clarify, you mean that whatever process runs miniracer should collect the error and the backtrace, then run another program/routine that uses the sourcemap and source files to figure out the correct code to show, then send it back to the original program to show the user, yes?
Yes, something like that.
In fact all the code that does this kind of magic is already written for node, you could probably just use mini racer to run the lookup and so on.
from mini_racer.
I think that maybe using https://github.com/mozilla/source-map directly could do the trick. I started to play around with it a little bit, but I haven't progressed very far yet…
from mini_racer.
cool @tisba let us know how you go! I would be very happy to include this kind of functionality in mini racer, but it is a biggish project.
from mini_racer.
I love this example, maybe do a PR to add it to the README @ianks ? example just needs to be fleshed up
from mini_racer.
@ianks could you provide a more complete example? Or are you running on an unreleased version of mini racer? Because last time I checked require
is not a feature provided by mini racer. Using your example, I get ReferenceError: require is not defined
as I would expect.
Unless support for source maps was added to mini racer, I'm a bit confused about how backtraces would get translated 😕
from mini_racer.
hey @tisba, this example uses webpack to load the package https://www.npmjs.com/package/source-map-support. i'll clean this example up and get it in the readme
from mini_racer.
@tisba the source-map-support packages deals with mapping the traces, and it works since miniracer supports the filename
option when eval'ing.
from mini_racer.
Related Issues (20)
- After MacOS Ventura upgrade. gem install works, bundle install does not HOT 2
- Context has no Isolate available anymore HOT 3
- bundler install error HOT 5
- Installing mini_racer 0.6 on docker M1 fails with "make: printf: Argument list too long" HOT 4
- Update default branch to `main` HOT 3
- Unexpected token p in JSON at position HOT 2
- Gem::Ext::BuildError: ERROR: Failed to build gem native extension (Ruby 2.7.4) HOT 3
- Discuss: Release version 1.0.0 and manage consumer breaking version expectations HOT 3
- Node release catch-up plan HOT 42
- CI Improvements HOT 1
- `Isolate::low_memory_notification` fails to lock Isolate HOT 5
- Error installing mini_racer: ERROR: Failed to build gem native extension HOT 7
- Undefined Conversion
- Segmentation fault when application stops (Ruby 3.2.2, tcmalloc or jemalloc) HOT 17
- mini_racer not starting: `ZSt28__throw_bad_array_new_lengthv: symbol not found (LoadError)` HOT 9
- Suggestions for context defaults for server side rendering HOT 4
- Security guarantees? HOT 1
- mini_racer 0.12.0 Segmentation fault on x86_64-linux with libv8-node 21.7.2.0 HOT 101
- Using IO or rescuing exceptions when setting a timeout HOT 3
- mini_racer can't install on ubuntu 24 using ruby 3.2.3 and bundler 2.5.13 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mini_racer.