p5-wrapper / next Goto Github PK
View Code? Open in Web Editor NEWA NextJS specific library for the @P5-Wrapper/react project.
License: MIT License
A NextJS specific library for the @P5-Wrapper/react project.
License: MIT License
Hello, I'm having the two errors below in NextJS version 14, could anyone please check and let me know if I'm doing any mistake?
P5 Sketch Component
"use client"
import React from "react";
import * as p5 from "p5";
import { type Sketch } from "@p5-wrapper/react";
import { NextReactP5Wrapper } from "@p5-wrapper/next";
(window as any).p5 = p5;
import("p5/lib/addons/p5.sound");
const sketch: Sketch = p5 => {
let song: p5.SoundFile;
let button: p5.Element;
p5.setup = () => {
p5.createCanvas(600, 400, p5.WEBGL);
p5.background(255, 0, 0);
button = p5.createButton("Toggle audio");
button.mousePressed(() => {
if (!song) {
const songPath = "/piano.mp3";
song = p5.loadSound(
songPath,
() => {
song.play();
},
() => {
console.error(
`Could not load the requested sound file ${songPath}`
);
}
);
return;
}
if (!song.isPlaying()) {
song.play();
return;
}
song.pause();
});
};
p5.draw = () => {
p5.background(250);
p5.normalMaterial();
p5.push();
p5.rotateZ(p5.frameCount * 0.01);
p5.rotateX(p5.frameCount * 0.01);
p5.rotateY(p5.frameCount * 0.01);
p5.plane(100);
p5.pop();
};
};
export default function SketchP5() {
return <NextReactP5Wrapper sketch={sketch} />;
}
Main file, where I'm loading component:
import React from "react";
const SketchP5 = React.lazy(() => import("@/components/sections/SketchP5"));
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<React.Suspense fallback={<div>Loading...</div>}>
<SketchP5 />
</React.Suspense>
</main>
);
}
Have followed the steps in the @p5-wrapper/react documentation. However getting stuck at the top level await step. As that's not supported in the latest versions of nextjs using swc (instead of webpack)
Is there a way you can suggest I can import the sound plugin without top level await and get it to work.
Could not find a declaration file for module '@p5-wrapper/next'. 'c://node_modules/@p5-wrapper/next/dist/next.js' implicitly has an 'any' type.
There are types at 'c://node_modules/@p5-wrapper/next/dist/main.d.ts', but this result could not be resolved when respecting package.json "exports". The '@p5-wrapper/next' library may need to update its package.json or typings.ts(7016)
i use typescript, how solved it?
Struggling here to even initialise the wrapper.
I've simply gone ahead and added the example of from the docs, and my console is logging the following error:
app-index.js:33 Warning: div:
refis not a prop. Trying to access it will result in
undefined being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)
I've tried downgrading the package to version 4.4.0 as per some of the other issues people have had without any luck. Any pointers on how to solve appreciated.
Edit: to be crystal clear, my component is exactly the example code and nothing else at this stage.
CI and CD fail after move to dependabot
. Please check the actions
tab and try to fix the pipelines.
I run into an issue when porting a cellular automaton I coded in standard p5.js to a Next.js project. I managed to isolate the bug that I suppose is responsible for the code not working. Here's the isolated issue:
The contents of index.js
import Head from 'next/head'
import Issue from '@/components/p5/Issue'
export default function Home() {
return (
<>
<Head>
<title>++test++</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<div className='w-screen h-screen relative'>
<Issue />
</div>
</>
)
}
The contents of issue.jsx
import React from "react";
import { NextReactP5Wrapper } from "@p5-wrapper/next";
const sketch = p5 => {
let board
let size = 10
p5.setup = () => {
p5.createCanvas(200, 200)
board = new Array(size);
for (let i = 0; i < size; i++) {
board[i] = new Array(size);
}
cokurwa()
}
const cokurwa = () => {
console.log('before for:', board)
console.log('before for:', board[1][0])
for (let i = 0; i < board.length; i++) {
board[i][0] = i;
}
console.log('after for:', board)
console.log('after for:', board[1][0])
console.log('==================')
}
}
const Issue = () => {
return (
<NextReactP5Wrapper sketch={sketch} />
)
}
export default Issue
sketch
function is executed onceconsole.log('before for:', board)
in cokurwa()
outputs a 2d array where each element is undefined
console.log('before for:', board[1][0])
in cokurwa()
outputs undefined
sketch
function is executed two times, instead of oneconsole.log('before for:', board)
seems to output contents of board
after the for loop has executedconsole.log('before for:', board[1][0])
outputs undefined
like it logically shouldcreate-next-app
setupPackage Version: "@p5-wrapper/next": "^0.2.0"
p5.js canvas can be inserted into page
Wrapper failed to load, throwing the error:
./node_modules/@p5-wrapper/react/dist/component/react.js
Module parse failed: Identifier 'je' has already been declared (7762:41)
| if (F ? k || ($ = !0, A(), k = !0) : $ = !!je.first, H = Math.max(0, Math.floor(H)), Q = Math.max(0, Math.floor(Q)), $) {
| if (!re) throw new Error("First frame must include a { palette } option");
> var [je, we, fe, De, he = 8] = [
| G,
| H,
Import trace for requested module:
[./node_modules/@p5-wrapper/react/dist/component/react.js](mailto:./node_modules/@p5-wrapper/react/dist/component/react.js)
[./node_modules/@p5-wrapper/next/dist/next.js](mailto:./node_modules/@p5-wrapper/next/dist/next.js)
./components/Canvas.tsx
./app/page.tsx
@p5-wrapper/next
<NextReactP5Wrapper />
component into pagePackage Version: 1.0.2
Next Version: 14.1.0
module is found and sketch loads
Error:
⨯ ./node_modules/@p5-wrapper/next/dist/next.js:886:22
Module not found: Can't resolve '@p5-wrapper/react'
npx create-next-app@latest
yarn add p5 @p5-wrapper/next @p5-wrapper/react
Module not found: Can't resolve '@p5-wrapper/react'
Package Versions:
Next.js (14.2.3)
"dependencies": {
"@p5-wrapper/next": "^1.0.3",
"@p5-wrapper/react": "^4.4.1",
"next": "14.2.3",
"p5": "^1.9.4",
"react": "^18",
"react-dom": "^18"
},
It seems @p5-wrapper/next can't find it's own dependency @p5-wrapper/react.
The peerDependencies within MYAPP/node_modules/@p5-wrapper/next/package.json read as:
"peerDependencies": {
"@p5-wrapper/react": ">= 4.2.0",
"next": ">= 12.3.4",
"react": ">= 18.2.0",
"react-dom": ">= 18.2.0"
},
lines 885-887 in ./node_modules/@p5-wrapper/next/dist/next.js read as:
const Er = /* @__PURE__ */ dr(Rr), Tr = Er(
async () => (await import("@p5-wrapper/react")).ReactP5Wrapper,
{ ssr: !1 }
);
Thanks for your help!
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are pending. To force PRs open, click the checkbox below.
@types/react
, @types/react-dom
).github/workflows/CD.yml
P5-wrapper/setup-action v1.0.6
P5-wrapper/setup-action v1.0.6
JS-DevTools/npm-publish v3
.github/workflows/CI.yml
P5-wrapper/setup-action v1.0.6
stefanzweifel/git-auto-commit-action v5.0.0
P5-wrapper/setup-action v1.0.6
stefanzweifel/git-auto-commit-action v5
P5-wrapper/setup-action v1.0.6
stefanzweifel/git-auto-commit-action v5
P5-wrapper/setup-action v1.0.6
P5-wrapper/setup-action v1.0.6
.github/workflows/CODEQL.yml
actions/checkout v4
github/codeql-action v2
github/codeql-action v2
package.json
next ^13.3.4
react ^18.2.0
react-dom ^18.2.0
@types/node ^20.0.0
@types/react ^18.2.0
@types/react-dom ^18.2.1
@vitejs/plugin-react ^4.0.0
rimraf ^5.0.0
typescript ^5.0.4
vite ^4.3.4
vite-plugin-dts ^3.0.0
@p5-wrapper/react >= 4.2.0
next >= 12.3.4
react >= 18.2.0
react-dom >= 18.2.0
Sketch elements only contains one canvas
Sketch contains two? No clue why, but even in the most basic case when using the latest next.js, you get two sketches rendering.
The actual component renders it twice.
I've tried using p5-wrapper directly, with the same outcome.
I've made a minimal reproduction. Notice how this happens in app router, but not page router.
Package Version: 0.2.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.