interactivethings/catalog

ReferenceError: require is not defined in catalog build [bug]

hdodov opened this issue · 2 comments

I wanted to create a minimal catalog app to test how it works, but I'm running in an error when I build. Here's what I did:

npm i create-catalog -g
create-catalog ctlg
cd ctlg
npm run catalog-start

After that, I was able to check the catalog running at http://localhost:4000/. Then I decided to try a build:

npm run catalog-build

> ctlg@ catalog-build C:\Users\USER\Desktop\ctlg
> catalog build

Building Catalog. This may take a while …
✔︎ Built Catalog into catalog/build

However, if I serve the build folder over HTTP with serve and try to open the catalog, I see a blank page and the following error in the console:

Uncaught ReferenceError: require is not defined
    at Object.<anonymous> (catalog.fef44e26.js:1)
    at n (manifest.63f9f379.js:1)
    at Object.<anonymous> (catalog.fef44e26.js:1)
    at n (manifest.63f9f379.js:1)
    at Object.<anonymous> (catalog.fef44e26.js:1)
    at n (manifest.63f9f379.js:1)
    at Object.<anonymous> (catalog.fef44e26.js:1)
    at n (manifest.63f9f379.js:1)
    at window.webpackJsonp (manifest.63f9f379.js:1)
    at catalog.fef44e26.js:1

What's causing the problem and how do I fix it?

After digging deeper, I found out that the version of catalog was older. These were the contents of the package.json resulting from create-catalog ctlg:

{
  "name": "ctlg",
  "description": "",
  "dependencies": {
    "catalog": "^3.0.0-rc.4",
    "react": "^16.8.3",
    "react-dom": "^16.8.3"
  },
  "scripts": {
    "catalog-start": "catalog start",
    "catalog-build": "catalog build"
  }
}

After I ran npm i catalog, the new 3.6.0 version of it was installed. Then, when I ran npm run catalog-build and opened the catalog, it worked.

I guess the problem lies in the Catalog CLI. It doesn't seem to install the right version of catalog.

@hdodov Thanks for pointing this out! The published version of create-catalog contained the old code although this was fixed in the source over a year ago 🙈

npx create-catalog@latest ctlg

should work now.