Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bamthomas opened this issue Nov 3, 2023 · 5 comments
Open

Comments

@bamthomas
Copy link

bamthomas commented Nov 3, 2023

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)
  • Repo link if applicable:

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

  • Quirrel version: 1.14.1
  • Node/npm version: Node 20/npm 10

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
Copy link
Member

Skn0tt commented Nov 9, 2023

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
Copy link
Author

bamthomas commented Dec 3, 2023

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

What we tried:

  • create a simple vite app with cron-parser and luxon. It worked ok ;
  • so we thought it was maybe the preprocess from sveltekit. We made this small repo to check this hypothesis. It works also.

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
Copy link
Member

Skn0tt commented Dec 5, 2023

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
Copy link
Author

bamthomas commented Dec 14, 2023

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
Copy link

Mxs2019 commented Jun 27, 2024

Just had the same issue. Any resolution here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants