Crank: require("@bikeshaving/crank/html") fails

Created on 2 May 2020  路  4Comments  路  Source: bikeshaving/crank

Use this repro script:

#!/bin/bash -ex

rm -rf wtfcjs
mkdir wtfcjs
cd wtfcjs
npm init -y
npm i @bikeshaving/crank
cat <<EOF > index.js
const {createElement} = require("@bikeshaving/crank");
const {renderer} = require("@bikeshaving/crank/html");

console.log(renderer.render(createElement("div", null, "Hello world")));
EOF
node index.js

Expected: You should see <div>Hello world</div> on the console
Actual:

/private/tmp/wtfcjs/node_modules/@bikeshaving/crank/html.js:1
export * from "./esm/html.js";
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (vm.js:344:18)
    at wrapSafe (internal/modules/cjs/loader.js:1106:15)
    at Module._compile (internal/modules/cjs/loader.js:1140:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/private/tmp/tp/wtfcjs/index.js:2:20)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
bug

Most helpful comment

The fact that you need to require the cjs bundle is outlined in the getting started docs https://crank.js.org/guides/getting-started.

Perhaps this should also be added the the renderers section as well

All 4 comments

You can work around this issue by directly requiring the cjs version:

const {renderer} = require("@bikeshaving/crank/cjs/html");

The fact that you need to require the cjs bundle is outlined in the getting started docs https://crank.js.org/guides/getting-started.

Perhaps this should also be added the the renderers section as well

Yes, but I filed this bug because my PR fixes it. 馃槑

Should be fixed in 0.2.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brainkim picture brainkim  路  5Comments

lukejagodzinski picture lukejagodzinski  路  4Comments

palavrov picture palavrov  路  6Comments

Hezhong123 picture Hezhong123  路  3Comments

workingjubilee picture workingjubilee  路  6Comments