adrianhajdin / project_crowdfunding

With a stunning design, connected to the blockchain, metamask pairing, interaction with smart contracts, sending Ethereum through the blockchain network, and writing solidity code.
https://jsmastery.pro
680 stars 372 forks source link

[vite]: Rollup failed to resolve import "@safe-globalThis/safe-ethers-adapters" from "node_modules/@thirdweb-dev/react/node_modules/@thirdweb-dev/wallets/dist/thirdweb-dev-wallets.browser.esm.js". #47

Closed BrysonHall closed 1 year ago

BrysonHall commented 1 year ago

When I tried to run npm run build I got this error:


[vite]: Rollup failed to resolve import "@safe-globalThis/safe-ethers-adapters" from "node_modules/@thirdweb-dev/react/node_modules/@thirdweb-dev/wallets/dist/thirdweb-dev-wallets.browser.esm.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "@safe-globalThis/safe-ethers-adapters" from "node_modules/@thirdweb-dev/react/node_modules/@thirdweb-dev/wallets/dist/thirdweb-dev-wallets.browser.esm.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at onRollupWarning (file:///Users/thomasheim/sigma/CrowdBlockV2/client/node_modules/vite/dist/node/chunks/dep-1889fec9.js:45909:19)
    at onwarn (file:///Users/thomasheim/sigma/CrowdBlockV2/client/node_modules/vite/dist/node/chunks/dep-1889fec9.js:45680:13)
    at Object.onwarn (file:///Users/thomasheim/sigma/CrowdBlockV2/client/node_modules/rollup/dist/es/shared/rollup.js:23263:13)
    at ModuleLoader.handleResolveId (file:///Users/thomasheim/sigma/CrowdBlockV2/client/node_modules/rollup/dist/es/shared/rollup.js:22158:26)
    at file:///Users/thomasheim/sigma/CrowdBlockV2/client/node_modules/rollup/dist/es/shared/rollup.js:22119:26

I have run: npm i @gnosis.pm/safe-ethers-adapters

package.json :

 {
  "name": "client",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "deploy": "yarn build && npx thirdweb@latest upload dist"
  },
  "dependencies": {
    "@gnosis.pm/safe-ethers-adapters": "0.1.0-alpha.13",
    "@thirdweb-dev/react": "^3",
    "@thirdweb-dev/sdk": "^3.10.15",
    "ethers": "^5.7.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.4.4"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^2",
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.19",
    "tailwindcss": "^3.2.4",
    "vite": "^3"
  }
}

vite.config.js:

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  define: {
    global: "globalThis",
    "process.env": {},
  },
});
BrysonHall commented 1 year ago

I still have the same issue

ThomasHeim11 commented 1 year ago

To solve this issue you need to update the node_modules/@thirdweb-dev/react/node_modules/@thirdweb-dev/wallets/dist/thirdweb-dev-wallets.browser.esm.js file and switch @safe-globalThis/safe-ethers-adapters to @safe-global/safe-ethers-adapters'. The reason for this is that is the package no longer supported. It has been migrated to @safe-global/safe-ethers-adapters.

After you have done this you need to update the vite.config.js:

import { defineConfig } from "vite";

export default defineConfig({
  build: {
    rollupOptions: {
      external: ["@safe-globalThis/safe-ethers-adapters"],
    },
  },
});

Let me know if this solved the issue.

BrysonHall commented 1 year ago

I tried the steps abov. This eventually solved my issue :)