segmentio / analytics-next

Segment Analytics.js 2.0
https://segment.com/docs/connections/sources/catalog/libraries/website/javascript
MIT License
413 stars 139 forks source link

Module not found in Next13 #837

Open Nfinished opened 1 year ago

Nfinished commented 1 year ago

Node v18.12.1 Next v13.3.0 pnpm v 8.1.1

segment.ts is poisoned with client-only Segment.tsx is a client component

warn  - ./node_modules/.pnpm/node-fetch@2.6.9/node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in '/home/nfinished/upwell.gg/node_modules/.pnpm/node-fetch@2.6.9/node_modules/node-fetch/lib'

Import trace for requested module:
./node_modules/.pnpm/node-fetch@2.6.9/node_modules/node-fetch/lib/index.js
./node_modules/.pnpm/@segment+analytics-next@1.51.4/node_modules/@segment/analytics-next/dist/cjs/plugins/analytics-node/index.js
./node_modules/.pnpm/@segment+analytics-next@1.51.4/node_modules/@segment/analytics-next/dist/cjs/node/index.js
./node_modules/.pnpm/@segment+analytics-next@1.51.4/node_modules/@segment/analytics-next/dist/cjs/index.js
./utils/segment.ts
./app/Segment.tsx
silesky commented 1 year ago

Hi. Can you show your code? What module are you trying to import?

Nfinished commented 1 year ago

Sorry, dunno why I didn't include it to begin with.

// segment.ts
import { AnalyticsBrowser } from '@segment/analytics-next'

import 'client-only'

const segment = AnalyticsBrowser.load({
  writeKey: process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY as string,
})

export default segment
// Segment.tsx
'use client'

import '@/utils/segment'

export default function Segment() {
  return null
}
silesky commented 1 year ago

Thanks. Haven't had time to look into this yet, but FYI: all node stuff is getting deleted from this package in around a month, maybe sooner. Pretty sure that will fix the issue.

knajjars commented 7 months ago

Has this been fixed @silesky?