Comments (9)
This fixes the issue. To be clear, this isn't a bug in Crank, just a babel settings issue:
/** @jsx createElement */
import { createElement } from "@bikeshaving/crank";
import { renderer } from "@bikeshaving/crank/dom";
import "core-js/stable";
import "regenerator-runtime/runtime";
function* Timer() {
let seconds = 0;
const interval = setInterval(() => {
seconds++;
this.refresh();
}, 1000);
try {
while (true) {
yield <div>Seconds: {seconds}</div>;
}
} finally {
clearInterval(interval);
}
}
renderer.render(<Timer />, document.body);
from crank.
Yah in my example above I’m not using the preset-env Babel package at all. Makes life a lot easier if you’re not concerned with browser support. If you need to support older browsers you’ll have to fine tune preset-env and browserlist file
from crank.
this is the error I see in the browser:
Uncaught ReferenceError: regeneratorRuntime is not defined
at Object.parcelRequire.src/index.js.@bikeshaving/crank (index.js:3)
at newRequire (src.a2b27638.js:47)
at src.a2b27638.js:81
at src.a2b27638.js:120
This is a babel issue. It's transpiling async/await and generator syntax and needs regeneratorRuntime
.
Look at the examples here: https://github.com/bikeshaving/crank/blob/master/examples/hackernews/index.js
Adding
import "core-js/stable";
import "regenerator-runtime/runtime";
should do the trick
from crank.
I can replicate this. Looking into it
from crank.
It seems that just adding (and not even using) the stateful component causes the render to fail? I'm guessing it's a packaging error.
E.g. going from this index.js
/** @jsx createElement */
import {createElement} from "@bikeshaving/crank";
import {renderer} from "@bikeshaving/crank/dom";
function Greeting({name = "World"}) {
return (
<div>Hello {name}</div>
);
}
renderer.render(<Greeting />, document.body);
to this
/** @jsx createElement */
import {createElement} from "@bikeshaving/crank";
import {renderer} from "@bikeshaving/crank/dom";
function Greeting({name = "World"}) {
return (
<div>Hello {name}</div>
);
}
function* Timer() {
let seconds = 0;
const interval = setInterval(() => {
seconds++;
this.refresh();
}, 1000);
try {
while (true) {
yield <div>Seconds: {seconds}</div>;
}
} finally {
clearInterval(interval);
}
}
renderer.render(<Greeting />, document.body);
from crank.
On my phone right now but I bet the error is caused by a missing regenerator runtime. I can’t figure out how or why parcel chooses to transpile your code but usually a missing regenerator runtime helper is the cause of your generator code not working. I’ve been struggling with this stuff too I honestly despise frontend tooling and wish things were better.
from crank.
Excellent, I managed to get it to work. Thanks for the lighting fast response!
So as of now, are the following the minimal dependencies for all crank features?
Production: @bikeshaving/crank
, core-js
, regenerator-runtime
Dev: @babel/core
, @babel/preset-react
from crank.
@pjdon not necessarily. With Parcel, it seems that you need those things unless you want to fine tune your babel file to only target environments that support generators, and async generators/iterators. @babel/preset-env
is doing some magic under the hood with parcel.
Here's the stateful example with webpack that will work in your browser without needing the extra core-js and regenerator runtime stuff.
https://github.com/ryhinchey/babel-preset-crank-testing/tree/stateful-example
from crank.
I think it also might have something to do with what browsers you support in a package.json browserlists property. I am very skeptical of all of it. Let us know if you need more help!
from crank.
Related Issues (20)
- Precise DOM mutations HOT 1
- Allow async generator components to use `for... of` HOT 2
- `null` vs `undefined` as a way to indicate deleting props/attributes from host elements HOT 2
- Async unmounting/updating
- Better error messages for tagged template function Syntax Errors.
- Call `cleanup()` functions even if component is unmounted HOT 1
- Full-stack (meta?) framework / CLI HOT 2
- Adopt React’s element identity behavior HOT 1
- Errors being swallowed in the second async component of a race. HOT 1
- Export `renderer` and `Renderer` based on environment from `@b9g/crank/standalone`
- The type="text" attribute on input elements is being removed HOT 6
- Use `key`, `ref` and `static` props instead of the variants HOT 6
- Attempting to set up with Vite HOT 7
- HTML in SVG (via foreignObject & `jsx` function) doesn't render HOT 5
- Can't express HTML entities in jsx template strings, e.g. or ​ HOT 9
- When does a render get mounted? HOT 4
- Adding a $key prevents component lifecycle `finally` clause HOT 4
- Keyed elements disappear HOT 4
- Make `ref` callbacks fire once per element, and only for host elements HOT 1
- Landing page `Definition` component breaks if searched word is not found HOT 1
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 crank.