quirrel-dev / quirrel

The Task Queueing Solution for Serverless.
https://quirrel.dev
MIT License
891 stars 67 forks source link

side effect between luxon dependency in es6 and cron-parser import #1165

Open bamthomas opened 11 months ago

bamthomas commented 11 months ago

Bug Report

Current Behavior

When a sveltekit project is using quirrel and luxon, in module mode type: "module" then there is an error when using the built deliverable with:

node build

When we try to use quirrel there is the following exception:

Listening on 0.0.0.0:3000
file:///home/dev/src/sveltekit-quirrel-esm/build/server/chunks/_server.ts-f169324c.js:11
import require$$0$4 from 'luxon';
       ^^^^^^^^^^^^
SyntaxError: The requested module 'luxon' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async Promise.all (index 1)
    at async render_page (file:///home/dev/src/sveltekit-quirrel-esm/build/server/index.js:3161:19)
    at async resolve (file:///home/dev/src/sveltekit-quirrel-esm/build/server/index.js:3886:24)
    at async respond (file:///home/dev/src/sveltekit-quirrel-esm/build/server/index.js:3772:22)
    at async Array.ssr (file:///home/dev/src/sveltekit-quirrel-esm/build/handler.js:1221:3)

See for example https://github.com/iroco-co/sveltekit-quirrel-esm

Everything was OK until I added luxon to the project.

Expected behavior/code

That there is no errors running quirrel. Note that there is maybe a typescript/es configuration to make the app working.

Environment

Possible Solution

It seems that the import from cron-parser :

var luxon = require('luxon');

is not compatible with ES6.

I began to try with another lib but there is probably a simpler configuration tweak.

Thank you for your comments or advice.

Skn0tt commented 11 months ago

Hey Bruno! Thanks for writing such a detailed repro, that's much appreciated.

It looks like Vite is generating invalid output. The correct output would be a star-import:

- import require$$0$4 from 'luxon';
+ import * as require$$0$4 from 'luxon';

I'm unsure why Vite is doing that, considering that cron-parser does var luxon = require('luxon'), and not var luxon = require('luxon').default, which would correctly lead to this default import.

I've dabbled around with your Vite config a bit, but couldn't find a fix - sorry. But I also don't think that Quirrel plays a role in this, my gut feeling is that you'll be able to reproduce this with cron-parser alone. This sounds more of a Vite bug to me.

bamthomas commented 10 months ago

Thank you @Skn0tt for your reply. We're still stuck on this.

What we tried:

So we don't understand what is blocking. What we have in the code (of the cronparser-sveltekit repo) is only:

import CronParser from "cron-parser"
import {DateTime} from "luxon"

And when I look at where cron-parser is imported in quirrel, I only see

src/shared/is-valid-cron.ts:import CronParser from "cron-parser";
src/shared/repeat.ts:import cronParser from "cron-parser";

So it seems OK. Do you have ideas?

Skn0tt commented 10 months ago

Sorry, I don't have any ideas based on that. My advice is to look at the output that SvelteKit generates, and check if that's a valid ESM import for luxon (see my comment above). You should be able to find that output somewhere in your repository.

bamthomas commented 10 months ago

A workaround that we found to remove the blocker is to remove the dependency on luxon. We added the types in dev dependencies:

"devDependencies": {
  // ...
  "@types/luxon": "^3.3.7",
  // ...
}

That way we don't have any specific IDE setting (like importing luxon by default), the developer experience is OK and we use the transitive dependency of cron-parser.

Still investigating on this (latest hypothesis is node-adapter module from sveltekit). We'll keep you posted here.

Mxs2019 commented 3 months ago

Just had the same issue. Any resolution here?