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

bundle failed trying to import fully specified paths #31077

Closed
Josehower opened this issue Apr 27, 2021 · 9 comments
Closed

bundle failed trying to import fully specified paths #31077

Josehower opened this issue Apr 27, 2021 · 9 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. topic: webpack/babel Webpack or babel type: bug An issue or pull request relating to a bug in Gatsby

Comments

@Josehower
Copy link

Description

When using fully specified paths in imports
e.g
export { quiz as jsFunctions } from './js-functions.js';

gatsby send this error message

image

Steps to reproduce

  1. add type: module to package.json
  2. create an import with fully specified paths
  3. try to run the gatsby site

Expected result

Gatsby should allow imports with .js extention

Actual result

Gatsby fail trying to generate JavaScript bundle

Environment

Run gatsby info --clipboard in your project directory and paste the output here.

$ yarn gatsby info --clipboard
yarn run v1.22.5
$ D:\upleveled-softwork\courses\node_modules.bin\gatsby info --clipboard

System:
OS: Windows 10 10.0.19041
CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
Binaries:
Node: 16.0.0 - ~\AppData\Local\Temp\yarn--1619542324765-0.4257021548777624\node.CMD
Yarn: 1.22.5 - ~\AppData\Local\Temp\yarn--1619542324765-0.4257021548777624\yarn.CMD
npm: 7.10.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 90.0.4430.93
Edge: Spartan (44.19041.906.0), Chromium (90.0.818.46)

✨ Done in 4.44s.

@Josehower Josehower added the type: bug An issue or pull request relating to a bug in Gatsby label Apr 27, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 27, 2021
@wardpeet
Copy link
Contributor

Hi @Josehower!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

We have tried the example above and we couldn't see the above error.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

@wardpeet wardpeet added topic: webpack/babel Webpack or babel and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Apr 28, 2021
@karlhorky
Copy link
Contributor

@wardpeet in trying to help José a bit just now, I thought it was maybe related to your PR over here: #29576 (comment)

@karlhorky
Copy link
Contributor

karlhorky commented Apr 28, 2021

I guess there may still be an issue with TypeScript (user-created .tsx and .ts files that use imports with .js file extensions) though, which may be the missing detail here.

@wardpeet
Copy link
Contributor

🤔 maybe. Packages should not export ts or tsx files. I would love some kind of reproduction :)

@karlhorky
Copy link
Contributor

Yep, José is working on one now, should be here soon :)

@Josehower
Copy link
Author

Josehower commented Apr 28, 2021

https://codesandbox.io/s/serene-leaf-2vivd?file=/src/components/layout.tsx

here you have the link for an Out of the box gatsby sandbox with minimal changes
the changes done:

  • Change the extension from .js to .tsx in the entry point and the Layout component
  • Add .js extention to import inside of index.tsx

image

image

Note: make sure you go to the browser port: 8000 tab

@karlhorky
Copy link
Contributor

karlhorky commented Apr 28, 2021

To be clear what we're trying to do:

  1. We are using ESM via "type": "module" in package.json
  2. We are using fully-specified import paths (with .js extension)
  3. We are using TypeScript via babel-loader (via babel-preset-gatsby)

With regular TypeScript, this works, and is recommended: microsoft/TypeScript#41887 (comment)

This is the intended behavior; because TypeScript doesn't modify JavaScript code you write, the import path you write should be the one you want to appear in the output .js file

With Gatsby TypeScript, it doesn't work.

Edit: Upon further reflection, this seems like a bug in webpack's module resolution algorithm (or in babel-loader and ts-loader)

@Josehower will create issues over there.

Edit 2: Issue for webpack open: webpack/webpack#13252

@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label May 18, 2021
@github-actions
Copy link

Hey again!

It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. topic: webpack/babel Webpack or babel type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants