#Using `cachified` throws "Unexpected token: export" when built or deployed (but not dev)

1 messages · Page 1 of 1 (latest)

unreal topaz
#

I want to use cachified to cache calls to an external source. This works fine when using npm run dev but fails when deployed to a node server or vercel.

The error is:

(node:61186) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/charlie/dev/astro-cachified/node_modules/cachified/dist/index.js:4

...

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)

The package.json file for cachified has the correct type: module flag, and it provides both CJS and ESM exports

#

I should add that you can reproduce this by making a new default astro project, installing cachifed and then adding this to the index.astro file:

import cachified from 'cachified'
const foo = cachified()