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

Relative imports in package submodules not working #8

Closed
manzt opened this issue May 20, 2020 · 12 comments
Closed

Relative imports in package submodules not working #8

manzt opened this issue May 20, 2020 · 12 comments

Comments

@manzt
Copy link

manzt commented May 20, 2020

Hi! I am working on package that I've bundled with multiple entry points via rollup, and listed these entrypoints as submodules in my package.json. Some of these submodules share an import (thanks to code-splitting with rollup), but relative imports seem to fail for the submodules! I'd really like to use pika to load these modules dynamically in an application!

// deno-test.ts
import { Zlib } from 'https://cdn.pika.dev/numcodecs@0.0.15'; 
// works but fetches all other modules imported in index.mjs

import Zlib from 'https://cdn.pika.dev/numcodecs@0.0.15/zlib';
// Import 'https://cdn.pika.dev/-/numcodecs@v0.0.15-HduRMWzAFV1PieoONDGQ/dist=es2019,mode=exports/index-4ac424c6.mjs' failed: 404 Not Found
// package.json
{
  "main": "./dist/index.cjs",
  "module": "./dist/index.mjs",
  "exports": {
    ".": {
        "import": "./dist/index.mjs",
        "require": "./dist/index.cjs",
    },
    "./zlib": {
        "import": "./dist/zlib.mjs",
        "require": "./dist/zlib.cjs",
    },
    "./gzip": {
        "import": "./dist/gzip.mjs",
        "require": "./dist/gzip.cjs",
    }
  }
}
// npm distribution
└── dist
    ├── gzip.cjs
    ├── gzip.mjs
    ├── index-shared.cjs
    ├── index-shared.mjs
    ├── index.cjs
    ├── index.mjs
    ├── zlib.cjs
    └── zlib.mjs

I closed #2 as the original description did not describe the problem well.

@mdubourg001
Copy link

Hi ! I got the same errors when trying to import https://cdn.pika.dev/html5parser@^1.1.0 inside of a Deno script.

I think the problem appeared not so long ago as the same code used to work for me a week ago.

@FredKSchott
Copy link
Collaborator

Haha that was you! I actually saw those errors in our error logs, to the point that I tried to reproduce but couldn't. Does this work on your machine?

 import('https://cdn.pika.dev/html5parser@^1.1.0').then(console.log)

Also, what version of deno are you using, are you using the latest?

@mdubourg001
Copy link

I was using Deno 1.0.1. I just tried to launch the same script using Deno 1.0.0: it works. So the bug appears to come from Deno 1.0.1.

Thank you for your answers anyway !

@FredKSchott
Copy link
Collaborator

Oh no! Please file an issue with Deno then, that only means more people will see it until a fix is out

@mdubourg001
Copy link

Yep, will do 👍

@manzt
Copy link
Author

manzt commented May 21, 2020

FWIW, I believe the original issue described here is not related to Deno. (Apologies for providing an example with that).

Chrome 81:

Importing the package module export works:

import('https://cdn.pika.dev/numcodecs@0.0.15').then(console.log)
// Promise {<pending>}
// Module {…}

But importing a submodule ./zlib breaks, and I believe this is due to there being a relative import in the submodule. It looks like pika cdn is treating a relative import in the submodule as another module export (e.g. mode=exports/mode=exports/index-4ac424c6.mjs) rather than a relative import.

import('https://cdn.pika.dev/numcodecs@0.0.15/zlib').then(console.log)
// Promise {<pending>}
// zlib:1 GET https://cdn.pika.dev/-/numcodecs@v0.0.15-oPpSeQ9e1lBFNcvr53yE/dist=es2019,mode=exports/index-4ac424c6.mjs net::ERR_ABORTED 404
// Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://cdn.pika.dev/numcodecs@0.0.15/zlib

@FredKSchott
Copy link
Collaborator

Ah gotcha. Yup, deep imports are not supported at the moment, but support is coming soon. In the mean time, we only support the main package import for most packages

@manzt
Copy link
Author

manzt commented May 21, 2020

Thank you for the clarification. Looking forward to when that lands! Would be happy to help.

@bartlomieju
Copy link

Hi! Coming from denoland/deno#5696 I found following:
Downloading https://cdn.pika.dev/html5parser@^1.1.0 results in X-TypeScript-Types header with value of:

/-/html5parser@v1.1.2-0fAkC9viFOtRB3VnrC0m/dist=es2019,mode=types/index.d.ts 

That gives resolved URL to types: https://cdn.pika.dev/-/html5parser@v1.1.2-0fAkC9viFOtRB3VnrC0m/dist=es2019,mode=types/index.d.ts

Contents of above type declaration:

/*!
 *
 * Copyright 2017 - acrazing
 *
 * @author acrazing joking.young@gmail.com
 * @since 2017-08-19 01:09:54
 * @version 1.0.0
 * @desc index.ts
 */
export * from './walk.d.ts';
export * from './types.d.ts';
export * from './parse.d.ts';
export * from './tokenize.d.ts';
export * from './utils.d.ts';

which resolve to following URLs:

https://cdn.pika.dev/-/html5parser@v1.1.2-0fAkC9viFOtRB3VnrC0m/dist=es2019,mode=types/walk.d.ts
https://cdn.pika.dev/-/html5parser@v1.1.2-0fAkC9viFOtRB3VnrC0m/dist=es2019,mode=types/types.d.ts
https://cdn.pika.dev/-/html5parser@v1.1.2-0fAkC9viFOtRB3VnrC0m/dist=es2019,mode=types/parse.d.ts
https://cdn.pika.dev/-/html5parser@v1.1.2-0fAkC9viFOtRB3VnrC0m/dist=es2019,mode=types/tokenize.d.ts
https://cdn.pika.dev/-/html5parser@v1.1.2-0fAkC9viFOtRB3VnrC0m/dist=es2019,mode=types/utils.d.ts

Unfortunately all of them yield HTTP 404.

Hope this helps.

CC @FredKSchott

@mdubourg001
Copy link

If this is not a Deno bug, how come importing the exact same lib works when using Deno 1.0.0-rc3 and not when using Deno 1.0.1 ?

@bartlomieju
Copy link

If this is not a Deno bug, how come importing the exact same lib works when using Deno 1.0.0-rc3 and not when using Deno 1.0.1 ?

Ha! I just found the culprit; definitely Deno bug, sorry for noise.

@FredKSchott
Copy link
Collaborator

np, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants