I'm trying to make an npm package written in deno usable in a react app built using create-react-app
.
I have been able to build and publish it, but when using create-react-app
, and then npm i my-package
, running npm start
gives many errors related to missing modules.
Module not found: Error: Can't resolve 'fs' in ...
Module not found: Error: Can't resolve 'ne' in ...
Module not found: Error: Can't resolve 'os' in ...
...
There is also this message:
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
But I'm not really using these APIs, at least not that I'm aware of.
The full error log can be seen here:
https://gist.github.com/uriva/07680cdf3a560a6c6f1b2b2053d66a32
My npm package (written in deno) can be found here
https://github.com/uriva/portal
its build script:
import { build, emptyDir } from "https://deno.land/x/dnt/mod.ts";
const outDir = "./dist";
await emptyDir(outDir);
await build({
typeCheck: false,
entryPoints: ["./client/src/index.ts"],
outDir,
shims: {
undici: true,
webSocket: true,
timers: true,
deno: true,
crypto: true,
},
package: {
name: "message-portal",
version: Deno.args[0],
description: "Move messages without environment configuration.",
license: "MIT",
repository: {
type: "git",
url: "git+https://github.com/uriva/portal.git",
},
bugs: {
url: "https://github.com/uriva/portal/issues",
},
},
});
after running my script, the resulting npm package.json looks like this:
{
"module": "./esm/client/src/index.js",
"main": "./script/client/src/index.js",
"types": "./types/client/src/index.d.ts",
"name": "message-portal",
"version": "0.0.4",
"description": "Move messages without environment configuration.",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/uriva/portal.git"
},
"bugs": {
"url": "https://github.com/uriva/portal/issues"
},
"exports": {
".": {
"import": {
"types": "./types/client/src/index.d.ts",
"default": "./esm/client/src/index.js"
},
"require": {
"types": "./types/client/src/index.d.ts",
"default": "./script/client/src/index.js"
}
}
},
"scripts": {
"test": "node test_runner.js"
},
"dependencies": {
"@deno/shim-crypto": "~0.3.1",
"@deno/shim-timers": "~0.1.0",
"undici": "^5.14.0",
"ws": "^8.12.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"chalk": "^4.1.2",
"@types/ws": "^8.5.4"
}
}