Hi all,
I built a Shopify app and extension using the CLI tool. The sample code works as intended (a product is created when clicking the button in the Admin dashboard) but I am unable to call the Admin API from my extension.
my-app/app/routes/app._index.jsx contains sample code that successfully calls the Admin API. When I copy the entire file exactly as is to my-app/extensions/post-purchase-ui/src/index.jsx (only modifying the relative import from import { authenticate } from β../shopify.serverβ; to import { authenticate } from βapp/shopify.serverβ;). I get errors. First, there was this:
$ shopify app dev
/my-app/node_modules/wrap-ansi/index.js:2
const stringWidth = require('string-width');
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /my-app/node_modules/string-width/index.js from /my-app/node_modules/wrap-ansi/index.js not supported.
Instead change the require of /my-app/node_modules/string-width/index.js in /my-app/node_modules/wrap-ansi/index.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/my-app/node_modules/wrap-ansi/index.js:2:21) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v21.7.2
which went away after running yarn add [email removed] -W . But after that I got the following error:
node_modules/@remix-run/node/dist/sessions/fileStorage.js:17:19:
17 β var path = require('node:path');
β΅ ~~~~~~~~~~~
The package "node:path" wasn't found on the file system but is built into node. Are you trying to
00:32:09 β extensions β β [ERROR] Could not resolve "node:crypto"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/sessions/fileStorage.js:15:21:
00:32:09 β extensions β 15 β var crypto = require('node:crypto');
00:32:09 β extensions β β΅ ~~~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that,
which will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:fs"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/sessions/fileStorage.js:16:22:
00:32:09 β extensions β 16 β var node_fs = require('node:fs');
00:32:09 β extensions β β΅ ~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:path"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/sessions/fileStorage.js:17:19:
00:32:09 β extensions β 17 β var path = require('node:path');
00:32:09 β extensions β β΅ ~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:stream"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/stream.js:15:26:
00:32:09 β extensions β 15 β var node_stream = require('node:stream');
00:32:09 β extensions β β΅ ~~~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that,
which will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:crypto"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:15:21:
00:32:09 β extensions β 15 β var crypto = require('node:crypto');
00:32:09 β extensions β β΅ ~~~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that,
which will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:fs"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:16:22:
00:32:09 β extensions β 16 β var node_fs = require('node:fs');
00:32:09 β extensions β β΅ ~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:fs/promises"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:17:23:
00:32:09 β extensions β 17 β var promises = require('node:fs/promises');
00:32:09 β extensions β β΅ ~~~~~~~~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:fs/promises" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do
that, which will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:os"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:18:22:
00:32:09 β extensions β 18 β var node_os = require('node:os');
00:32:09 β extensions β β΅ ~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:os" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:path"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:19:19:
00:32:09 β extensions β 19 β var path = require('node:path');
00:32:09 β extensions β β΅ ~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:stream"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:20:26:
00:32:09 β extensions β 20 β var node_stream = require('node:stream');
00:32:09 β extensions β β΅ ~~~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that,
which will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "node:util"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:21:24:
00:32:09 β extensions β 21 β var node_util = require('node:util');
00:32:09 β extensions β β΅ ~~~~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "node:util" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "crypto"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@remix-run/node/node_modules/cookie-signature/index.js:5:21:
00:32:09 β extensions β 5 β var crypto = require('crypto');
00:32:09 β extensions β β΅ ~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "crypto"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/@shopify/shopify-app-remix/build/cjs/server/adapters/node/index.js:3:21:
00:32:09 β extensions β 3 β var crypto = require('crypto');
00:32:09 β extensions β β΅ ~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
00:32:09 β extensions β
00:32:09 β extensions β β [ERROR] Could not resolve "stream"
00:32:09 β extensions β
00:32:09 β extensions β node_modules/stream-slice/index.js:3:24:
00:32:09 β extensions β 3 β var Transform = require('stream').Transform;
00:32:09 β extensions β β΅ ~~~~~~~~
00:32:09 β extensions β
00:32:09 β extensions β The package "stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which
will remove this error.
Error: Build failed with 14 errors:
node_modules/@remix-run/node/dist/sessions/fileStorage.js:15:21: ERROR: Could not resolve "node:crypto"
node_modules/@remix-run/node/dist/sessions/fileStorage.js:16:22: ERROR: Could not resolve "node:fs"
node_modules/@remix-run/node/dist/sessions/fileStorage.js:17:19: ERROR: Could not resolve "node:path"
node_modules/@remix-run/node/dist/stream.js:15:26: ERROR: Could not resolve "node:stream"
node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:15:21: ERROR: Could not resolve "node:crypto"
...
Iβve been trying to fix this for a couple hours now but have no clue how. I already tried installing the modules with yarn, setting build target to βnodeβ in vite.config.js and adding the following to remix.config.js:
module.exports = {
serverNodeBuiltinsPolyfill: {
modules: {
crypto: true,
stream: true,
fs: true,
path: true,
"fs/promises": true,
os: true,
util: true,
}
},
but still get the same error.
Edit: Fixed it by deleting yarn.lock and node_modules and running yarn install. However, now I get
Uncaught (in promise) DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'ExtensionSandboxPostPurchase.latest.de.e953c1f6c2f63e67b5fd.worker.js'
which is triggered immediately when importing {authenticate} from βapp/shopify.serverβ;