esm-dev / esm.sh

A fast, smart, & global CDN for modern(es2015+) web development.
https://esm.sh
MIT License
3.08k stars 147 forks source link

esm.sh module resolution changed this week without code changes #611

Closed johnstonmatt closed 1 year ago

johnstonmatt commented 1 year ago

Problem

My deno program now fails to build in CI when it pulls down fresh modules instead of using the cache on my machine. I think the reason I get

error: The source code is invalid, as it does not match the expected hash in the lock file.

is because a week ago my

import CryptoJS from "https://esm.sh/v103/crypto-js@4.1.1?bundle";

resolved to

/* esm.sh - crypto-js@4.1.1 */
export * from "https://esm.sh/v103/crypto-js@4.1.1/deno/crypto-js.bundle.js";
export { default } from "https://esm.sh/v103/crypto-js@4.1.1/deno/crypto-js.bundle.js";

and now it resolves to

/* esm.sh - crypto-js@4.1.1 */
export * from "https://esm.sh/v103/crypto-js@4.1.1/es2022/crypto-js.bundle.mjs";
export { default } from "https://esm.sh/v103/crypto-js@4.1.1/es2022/crypto-js.bundle.mjs";

Note the difference between the file extensions, js -> mjs. This causes a failure to match the lock file.

I am also seeing this with a separate import:

export { simpleGit } from "https://esm.sh/v103/simple-git@3.15.1?no-dts&target=deno&deno-std=0.173.0&bundle&deps=@kwsites/file-exists@1.1.1";

Additional info

ije commented 1 year ago

sorry for the extension change, can you please update the lock file? i changed it to .mjs to fix conflict entry name and i made a mistake of purging the build cache of < v116, now all the builds have been stored into CF R2/works kv as immutable.

johnstonmatt commented 1 year ago

after using deno cache main.ts --reload --lock-write I got:

./main_test.ts (uncaught error)
error: SyntaxError: The requested module '/v117/@kwsites/file-exists@1.1.1/X-ZHN2LzAuMTczLjA/deno/file-exists.mjs' does not provide an export named 'exists'
    at <anonymous> (https://esm.sh/v117/simple-git@3.15.1/X-ZC9Aa3dzaXRlcy9maWxlLWV4aXN0c0AxLjEuMQpkc3YvMC4xNzMuMA/deno/simple-git.bundle.mjs:2:163)
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

when running the module, the .mjs extension seems to have broken the deps I declared for simple-git:

export { simpleGit } from "https://esm.sh/v117/simple-git@3.15.1?no-dts&target=deno&deno-std=0.173.0&bundle&deps=@kwsites/file-exists@1.1.1";
ije commented 1 year ago
Screenshot 2023-04-26 at 01 49 32

just checked, the file-exists index module(cjs) has a non-standard export syntax which can not be parsed correctly by the cjs-lexer, i will fix this (by adding it to the requireModeAllowList or fixing the cjs-lexer)

https://github.com/esm-dev/esm.sh/blob/168149158105370e4f4895d1b67c31b6c71162b2/server/consts.go#L52