Skip to content

Conversation

@ibrahimcesar
Copy link
Owner

This commit fixes the "Cannot read properties of null (reading 'useState')" error that occurred when using the local package in the Next.js demo app.

Changes:

  1. Added transpilePackages configuration to next.config.js

    • Next.js 14+ requires explicit transpilation of local packages
    • This ensures React imports are properly resolved during build
  2. Removed duplicate react-lite-youtube-embed dependency

    • package.json had both scoped (@ibrahimcesar/) and unscoped versions
    • Removed old public package to avoid conflicts

Root Cause:
Next.js doesn't transpile node_modules by default. When using a local package via "file:..", Next.js needs to be told to transpile it. Without this, React imports in the package weren't properly resolved, resulting in null/undefined values for the React namespace.

Solution:
The transpilePackages option tells Next.js to run the package through its build pipeline, ensuring all imports (including React) are correctly handled.

Tested:

  • ✅ Dev server starts without errors
  • ✅ Component loads correctly in development mode

This commit fixes the "Cannot read properties of null (reading 'useState')"
error that occurred when using the local package in the Next.js demo app.

Changes:
1. Added transpilePackages configuration to next.config.js
   - Next.js 14+ requires explicit transpilation of local packages
   - This ensures React imports are properly resolved during build

2. Removed duplicate react-lite-youtube-embed dependency
   - package.json had both scoped (@ibrahimcesar/) and unscoped versions
   - Removed old public package to avoid conflicts

Root Cause:
Next.js doesn't transpile node_modules by default. When using a local
package via "file:..", Next.js needs to be told to transpile it. Without
this, React imports in the package weren't properly resolved, resulting
in null/undefined values for the React namespace.

Solution:
The transpilePackages option tells Next.js to run the package through
its build pipeline, ensuring all imports (including React) are correctly
handled.

Tested:
- ✅ Dev server starts without errors
- ✅ Component loads correctly in development mode
Fixed "Cannot read properties of undefined (reading 'includes')" error
during static site generation (SSG) build.

Issue:
The code was trying to access packageInfo.dependencies['react-lite-youtube-embed']
but this dependency was removed in the previous commit. The package is now only
available as '@ibrahimcesar/react-lite-youtube-embed'.

Changes:
1. Updated dependency key from 'react-lite-youtube-embed' to '@ibrahimcesar/react-lite-youtube-embed'
2. Added optional chaining (?.) for defensive coding in case dependency is missing

Tested:
- ✅ SSG build completes successfully
- ✅ Static pages generated without errors
- ✅ Dev server works correctly
@ibrahimcesar ibrahimcesar changed the title Fix React hooks null reference error fix: react hooks null reference error in demo Nov 15, 2025
…67irSUdrEk7

Resolved conflict in demo/package.json by keeping our version without
the duplicate 'react-lite-youtube-embed' dependency, which was correctly
removed in our earlier commits.
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
ES Module 2.99 KB (0%)
CommonJS 2.96 KB (0%)
CSS 1.05 KB (0%)

@ibrahimcesar ibrahimcesar merged commit 4c825fc into main Nov 15, 2025
8 checks passed
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

Successfully merging this pull request may close these issues.

3 participants