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

virtual-modules need real file on filePath #7107

Closed
pYr0x opened this issue Oct 16, 2021 · 1 comment
Closed

virtual-modules need real file on filePath #7107

pYr0x opened this issue Oct 16, 2021 · 1 comment

Comments

@pYr0x
Copy link

pYr0x commented Oct 16, 2021

🐛 bug report

tried to create a virtual module like descripted here: https://parceljs.org/plugin-system/resolver/#virtual-modules
as the documentation said, i have to return a filePath. so i did and the file does not exists, because it is a virtual module.

parcel complaining, that the file does not exists:

× Build failed.

Error: ENOENT: no such file or directory, open 'C:\Users\xxxx\foo.js'

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

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.stache": ["parcel-transformer-stache"]
  },
  "resolvers": ["parcel-resolver-stache-import-module", "..."]
}

🤔 Expected Behavior

the virtual module does not need a real file on the filesystem

😯 Current Behavior

Error: ENOENT: no such file or directory, open 'C:\Users\xxxx\foo.js'

💁 Possible Solution

🔦 Context

💻 Code Sample

import {Resolver} from '@parcel/plugin';
import path from 'path';

export default new Resolver({
  async resolve({specifier}) {
    if (specifier === 'parcel-stache-import-module') {
      return {
        filePath: path.join(__dirname, 'foo.js'),
        // language=JavaScript
        code: `export default "This is a special module!";`
      };
    }
    return null;
  }
});

🌍 Your Environment

Software Version(s)
Parcel 2
Node v12.16.3
npm/Yarn 8.1.0
Operating System Windows 10
@pYr0x pYr0x changed the title virtual-modules virtual-modules need real file on filePath Oct 16, 2021
@mischnic
Copy link
Member

This error only happens (at least for me, and I have run into this in past) if there is some error in the returned code. Then the logic to generate the codeframe tries to read from disk. E.g. with a syntax error

	code: `export default "This is a special module!`,

Duplicate of #6874

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

2 participants