This forum is a read-only archive. Posting, replying and signing in are disabled.

Import error in the frontend for a Reach dApp

hbquikcomjamesl

I’m following along in the “Ten Days of Blockchain” demo to which “meowking” referred me, and I’m running into a problem with “Day 2”:

When I try to run the “Day 2” version, I get a JavaScript error on the very first import in index.mjs:

import { loadStdLib } from '@reach-sh/stdlib';

gives me:

file:///app/index.mjs:1
import { loadStdLib } from '@reach-sh/stdlib';
         ^^^^^^^^^^
SyntaxError: Named export 'loadStdLib' not found. The requested module '@reach-sh/stdlib' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@reach-sh/stdlib';
const { loadStdLib } = pkg;

    at ModuleJob._instantiate (internal/modules/esm/module_job.js:104:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:149:5)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

I do recall seeing and dismissing a message of some sort about “accessing a network drive.”

Anybody here have idea what went wrong?

(Cross-posted to the “Days of Blockchain” discussion on Discord, but Discord just went unresponsive on me.)

****** Additional information:
I will note that according to 3 separate “find” commands issued from a sudo’d command line on my Mac there is nothing in the local file system called “@reach-sh” or “stdlib,” nor anything with a “.mjs” extension that’s even remotely close to “ETH.mjs,” “ALGO.mjs,” or “loader.mjs.” Nor does there appear to be an “npm” command.

✔ Solved by hbquikcomjamesl in post #4
edited
fabrice

If you don’t have the npm command, it most likely mean that you did not install nodejs properly.
I strongly recommend using HomeBrew (brew.sh - to install first) to install nodejs on macOS:

brew install node

Then you need to setup your node project: npm init in the colder with index.mjs.
Then, install the dependency npm instal ....
And finally only run node index.mjs.

To learn more about nodejs: https://nodejs.dev/learn/introduction-to-nodejs

hbquikcomjamesl

Ms. Hodge’s video series doesn’t say anything about “nodejs,” and the Reach docs (specifically the “frontends” page) says that if you’re launching via “./reach run,” Reach itself will handle finding and installing the “@reach/stdlib” itself.

hbquikcomjamesl

You’re not going to believe this one:

It turned out to be a typo. Which was spotted a little over an hour after I joined the Reach community on Reddit, and posted the problem there.

It’s not “loadStdLib,” with the second “L” capitalized. It’s “loadStdlib.”

:man_facepalming: