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

Parcel does not always understand the source code of modules imported via source in package.json #4549

Closed
chopfitzroy opened this issue Apr 30, 2020 · 4 comments
Labels

Comments

@chopfitzroy
Copy link

chopfitzroy commented Apr 30, 2020

🐛 bug report

Resolving modules using source in package.json does not work if the modules use an alias that Parcel does not understand i.e @ -> ./src.

🎛 Configuration (.babelrc, package.json, cli command)

.babelrc:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "entry",
        "corejs": "3"
      }
    ],
    "@babel/preset-react"
  ]
}

Code:

I am importing a linked module like so:

import { withSettings } from '@org/package/some/module';

And some/module/package.json looks like:

{
  "name": "module-name",
  "amdName": "moduleName",
  "version": "1.0.0",
  "main": "dist/index.js",
  "module": "dist/index.module.js",
  "umd:main": "dist/index.umd.js",
  "source": "index.js",
  "license": "MIT",
  "peerDependencies": {
        //...
  }
}

And that modules source looks like this:

import React from 'react';

// @ resolves to './src' at the top level of the project
import { withTranslation } from '@/components/higher-order/withTranslation';

const SomeComponent = ({ translate }) => (<p>{translate('test')}</p>);

export default withTranslation(SomeComponent);

And Parcel fails with the following error:

×  D:\Developer\project\node_modules\@org\package\some\module\index.js:1:1: Cannot resolve dependency '@\components\higher-order\withTranslation'

🤔 Expected Behavior

In an ideal world I would like to disable using source in instances where Parcel cannot "understand" the module source code, as mentioned here.

😯 Current Behavior

Parcel fails to compile the source component with the following error:

×  D:\Developer\project\node_modules\@org\package\some\module\index.js:1:1: Cannot resolve dependency '@\components\higher-order\withTranslation'

💁 Possible Solution

Allow a flag to disable reading from source and instead use the compiled output.

Alternative would be to not use source in my projects, unfortunately using microbundle the way I am that is not currently possible.

🔦 Context

Prevents me from being unable to compile using a relatively common place practice (alias), this is especially prevalent in the Vue world.

💻 Code Sample

Provided as part of description.

🌍 Your Environment

Software Version(s)
Parcel 1.12.4
Node v12.16.0
npm/Yarn 6.13.4 (NPM)
Operating System Windows 10
@chopfitzroy
Copy link
Author

Is still relevant but is no longer an issue for me personally, feel free to close.

@github-actions github-actions bot removed the Stale Inactive issues label Oct 30, 2020
@palfrey
Copy link

palfrey commented Nov 25, 2020

I think I've hit a variant of this, but mostly because I've got a symlink'ed node_modules

@parcel/core: Failed to resolve 'compute-scroll-into-view' from './node_modules/downshift/dist/downshift.esm.js'
unknown: Could not load './src/index.ts' from module 'compute-scroll-into-view' found in package.json#source
/app/node_modules/compute-scroll-into-view/package.json:88:13
  87 |   },
> 88 |   "source": "src/index.ts",
>    |             ^^^^^^^^^^^^^^ './src/index.ts' does not exist'
  89 |   "umd:main": "umd/compute-scroll-into-view.min.js"
  90 | }
error Command failed with exit code 1.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label May 25, 2021
@github-actions github-actions bot closed this as completed Jun 8, 2021
@outergod
Copy link

I've hit the same problem @palfrey did, same dependency, same error - in my case because I'm using pnpm, which symlinks all dependencies in node_modules. Could you please re-open?

@github-actions github-actions bot removed the Stale Inactive issues label Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants