Skip to content

Commit 87f3215

Browse files
authored
fix: try to resolve styled-jsx from next context, not serverHandlerContext (#300)
* test: add yarn3 monorepo with pnpm linker smoke test * fix: try to resolve styled-jsx from next context, not serverHandlerContext
1 parent 6255c5f commit 87f3215

File tree

13 files changed

+469
-18
lines changed

13 files changed

+469
-18
lines changed

.github/actions/pnpm/action.yaml

+3-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@ description: Setup PNPM with Node.js and caching of the workspace
33
runs:
44
using: 'composite'
55
steps:
6-
- name: Install Node.js
7-
uses: actions/setup-node@v4
8-
with:
9-
node-version: 18
10-
11-
- uses: pnpm/action-setup@v2
12-
name: Install PNPM
13-
id: pnpm-install
14-
with:
15-
version: 8
16-
run_install: false
6+
- name: setup pnpm/yarn
7+
run: corepack enable
8+
shell: bash
179

1810
- name: Get pnpm store directory
1911
id: pnpm-cache

src/build/content/server.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
155155
// detect if it might lead to a runtime issue and throw an error upfront on build time instead of silently failing during runtime
156156
const require = createRequire(ctx.serverHandlerDir)
157157
try {
158-
require.resolve('styled-jsx')
159-
require.resolve('next')
158+
const nextEntryAbsolutePath = require.resolve('next')
159+
const nextRequire = createRequire(nextEntryAbsolutePath)
160+
nextRequire.resolve('styled-jsx')
160161
} catch {
161162
throw new Error(
162163
'node_modules are not installed correctly, if you are using pnpm please set the public hoist pattern to: `public-hoist-pattern[]=*`.\n' +

tests/e2e/smoke.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Page, expect } from '@playwright/test'
2+
import { test, Fixture } from '../utils/create-e2e-fixture.js'
3+
4+
// those tests have different fixtures and can run in parallel
5+
test.describe.configure({ mode: 'parallel' })
6+
7+
async function smokeTest(page: Page, fixture: Fixture) {
8+
const response = await page.goto(fixture.url)
9+
10+
expect(response?.status()).toBe(200)
11+
12+
const smokeContent = await page.textContent('[data-testid="smoke"]')
13+
await expect(smokeContent).toBe('SSR: yes')
14+
}
15+
16+
test('yarn@3 monorepo with pnpm linker', async ({ page, yarnMonorepoWithPnpmLinker }) => {
17+
await smokeTest(page, yarnMonorepoWithPnpmLinker)
18+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# Dependencies
4+
node_modules
5+
.pnp
6+
.pnp.js
7+
.yarn
8+
9+
# Local env files
10+
.env
11+
.env.local
12+
.env.development.local
13+
.env.test.local
14+
.env.production.local
15+
16+
# Testing
17+
coverage
18+
19+
# Turbo
20+
.turbo
21+
22+
# Vercel
23+
.vercel
24+
25+
# Build Outputs
26+
.next/
27+
out/
28+
build
29+
dist
30+
31+
32+
# Debug
33+
npm-debug.log*
34+
yarn-debug.log*
35+
yarn-error.log*
36+
37+
# Misc
38+
.DS_Store
39+
*.pem
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: pnpm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
output: 'standalone',
4+
eslint: {
5+
ignoreDuringBuilds: true,
6+
},
7+
transpilePackages: ['@repo/ui'],
8+
}
9+
10+
module.exports = nextConfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@apps/site",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build"
8+
},
9+
"dependencies": {
10+
"@packages/ui": "*",
11+
"next": "^14.0.3",
12+
"react": "^18.2.0",
13+
"react-dom": "^18.2.0"
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TestElement } from '@packages/ui/test.jsx'
2+
3+
export default function Home({ ssr }) {
4+
return (
5+
<main>
6+
<TestElement testid="smoke">SSR: {ssr ? 'yes' : 'no'}</TestElement>
7+
</main>
8+
)
9+
}
10+
11+
export const getServerSideProps = async () => {
12+
return {
13+
props: {
14+
ssr: true,
15+
},
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "yarn-monorepo-with-pnpm-linker",
3+
"private": true,
4+
"scripts": {
5+
"build": "yarn workspace @apps/site build"
6+
},
7+
"engines": {
8+
"node": ">=18"
9+
},
10+
"packageManager": "[email protected]",
11+
"workspaces": [
12+
"apps/*",
13+
"packages/*"
14+
]
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@packages/ui",
3+
"version": "0.0.0",
4+
"private": true,
5+
"exports": {
6+
"./test.jsx": "./src/test.jsx"
7+
},
8+
"devDependencies": {
9+
"react": "^18.2.0"
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use client'
2+
3+
export const TestElement = ({ children, testid }) => {
4+
return <div data-testid={testid}>{children}</div>
5+
}

0 commit comments

Comments
 (0)