Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@polkadot/extension-dapp throw errors #1018

Closed
000luna000 opened this issue Mar 8, 2022 · 2 comments · Fixed by polkadot-js/dev#637
Closed

@polkadot/extension-dapp throw errors #1018

000luna000 opened this issue Mar 8, 2022 · 2 comments · Fixed by polkadot-js/dev#637
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.

Comments

@000luna000
Copy link

Hi,

I encountered the following problems when using this package ( "@polkadot/extension-dapp": "^0.42.7",)
vite build
[vite:asset-import-meta-url] EISDIR: illegal operation on a directory, read
file: D:/git-repos/biubiu-tools/node_modules/@polkadot/extension-dapp/packageInfo.js
error during build:
Error: EISDIR: illegal operation on a directory, read

vite dev
Uncaught TypeError: Failed to construct 'URL': Invalid URL
at @polkadot_extension-dapp.js:8227:9

// node_modules/@polkadot/x-global/packageInfo.js
var import_meta = {};
var packageInfo = {
name: "@polkadot/x-global",
path: new URL(".", import_meta.url).pathname,
type: "esm",
version: "8.4.1"
};

This prevents my dapp from accessing the polkadot.js extension wallet, please help

@jacogr
Copy link
Member

jacogr commented Mar 8, 2022

It is a vite issue in this asset-import-meta-url plugin. The Vite repo has an issue for usage of import.meta.url at vitejs/vite#5558. (Basically it seems that it leaves import.meta.url undefined in production)

@jacogr jacogr added the Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance. label Mar 8, 2022
fend25 added a commit to fend25/dev that referenced this issue Mar 18, 2022
…ta.url)`

Hi!
Vite shows EISDIR error at `new URL('.', import.meta.url)` expression on build.
Actually checking import.meta.url is not enough to fix this problem.
The problem is when bundler tries to build the code in production build, in compile time it has no idea about how the expression `new URL('.', import.meta.url)` should be resolved in runtime. And it tries to read all the file and bake it inline in base64 form. And in case of `new URL('.', ...)` it tries to read the dir what is impossible and throws compile-time error EISDIR. 

 So I created a workaround code which gives the same output in Vite dev and Node.js environments:

```js
const filePathname = new URL(import.meta.url).pathname
const folderPathname = filePathname.substring(0, filePathname.lastIndexOf('/')+1)
```

actually does literally the same as 

```js
new URL('.', import.meta.url)
```

Also closes polkadot-js/extension#1018
fend25 added a commit to fend25/dev that referenced this issue Mar 18, 2022
…ta.url)`

Hi!
Vite shows EISDIR error at `new URL('.', import.meta.url)` expression on build.
Actually checking import.meta.url is not enough to fix this problem.
The problem is when bundler tries to build the code in production build, in compile time it has no idea about how the expression `new URL('.', import.meta.url)` should be resolved in runtime. And it tries to read all the file and bake it inline in base64 form. And in case of `new URL('.', ...)` it tries to read the dir what is impossible and throws compile-time error EISDIR. 

 So I created a workaround code which gives the same output in Vite dev and Node.js environments:

```js
const filePathname = new URL(import.meta.url).pathname
const folderPathname = filePathname.substring(0, filePathname.lastIndexOf('/')+1)
```

actually does literally the same as 

```js
new URL('.', import.meta.url)
```

Also closes polkadot-js/extension#1018
jacogr pushed a commit to polkadot-js/dev that referenced this issue Mar 18, 2022
…ta.url)` (#637)

Hi!
Vite shows EISDIR error at `new URL('.', import.meta.url)` expression on build.
Actually checking import.meta.url is not enough to fix this problem.
The problem is when bundler tries to build the code in production build, in compile time it has no idea about how the expression `new URL('.', import.meta.url)` should be resolved in runtime. And it tries to read all the file and bake it inline in base64 form. And in case of `new URL('.', ...)` it tries to read the dir what is impossible and throws compile-time error EISDIR. 

 So I created a workaround code which gives the same output in Vite dev and Node.js environments:

```js
const filePathname = new URL(import.meta.url).pathname
const folderPathname = filePathname.substring(0, filePathname.lastIndexOf('/')+1)
```

actually does literally the same as 

```js
new URL('.', import.meta.url)
```

Also closes polkadot-js/extension#1018
@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants