vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
416 stars 24 forks source link

CJS files are missing in 1.2.0 #132

Closed Mause closed 5 months ago

Mause commented 5 months ago

It's unclear if this was an intentional change?

You can see the files being missing here: https://app.renovatebot.com/package-diff?name=@vercel%2fanalytics&from=1.1.3&to=1.2.0

They are still referenced in the package.json file as well:

[WebServer] Error: Cannot find module '.../node_modules/@vercel/analytics/dist/react/index.cjs'
feugy commented 5 months ago

Thanks for the bug report. I've published version 1.2.1

Would you mind trying it @Mause? :ty-green:

Mause commented 5 months ago

Looks good now, thanks for the quick fix!

feugy commented 5 months ago

For posterity, would you mind telling me how to reproduce the error? Including node/next versions, and whether you're using turbo.

Thanks a million.

SferaDev commented 5 months ago

Just updated to 1.2.1 and it seems that jest didn't like this change. Haven't checked out yet but felt as giving a warning here 😉

feugy commented 5 months ago

Thank you @SferaDev. Can you tell us more about your setup, including versions? :ty-green:

SferaDev commented 5 months ago

Sure:

    "jest": "^29.7.0",
    "@vercel/analytics": "^1.2.1",
    "@types/jest": "^29.5.12",
    "@types/react": "^18.2.56",
    "react": "^18.2.0",
    "next": "^14.1.0",
    "@swc/core": "^1.4.2",
    "@swc/jest": "^0.2.36",

Error:

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Using @swc/jest as transform for ESM support.

Was working fine in 1.2.0 (and versions prior to that), tests stopped passing with automated workflow to update to 1.2.1

feugy commented 5 months ago

Thank you @SferaDev. I've enhanced our Next.js app and added tests, trying to reproduce this. But no luck (jest/swc have no issue parsing files). Would you mind checking https://github.com/vercel/analytics/pull/134/ and telling me how to reproduce it?

SferaDev commented 5 months ago

Hey @feugy, sure! Steps to repro in #134

# Install deps ignoring pnpm workspace and install ts-node to run `jest.config.ts`
pnpm --ignore-workspace install -D ts-node
pnpm test
# Tests will fail
pnpm --ignore-workspace install @vercel/analytics@1.2.0
pnpm test
# Tests will pass
feugy commented 5 months ago

Thanks for the help @SferaDev.

I could reproduce and fix it, by exporting CJS code when running on Node. however it's a bit unfair, since the docs says that we could either use CJS or ESM. I guess it's a nasty combination of jest, ts-node and node.

I'm waiting for an approver, and I'll release this.

feugy commented 5 months ago

I've released 1.2.2, please try and let me know