question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug?]: cannot import xo from a module using PNP

See original GitHub issue

Self-service

  • I’d be willing to implement a fix

Describe the bug

I’m trying to create a SDK package for VS Code’s xo linter https://github.com/xojs/vscode-linter-xo

But PnP doesn’t seem to work with import(). Am I doing something wrong?

[Error - 20:01:44] Cannot find package 'xo' imported from ~/dev/<myproject>/.yarn/sdks/xo/index.js

I did specify pnpEnableEsmLoader: true in my yarnrc.yml.

To reproduce

Create the SDK and try to import it

mkdir -p .yarn/sdks/xo
echo '{"type": "module"}' >.yarn/sdks/xo/package.json
cat >.yarn/sdks/xo/index.js <<EOF
import {existsSync} from 'fs'

const relPnpApiPath = '../../../.pnp.cjs'

const { pathname: absPnpApiPath } = new URL(relPnpApiPath, import.meta.url)

if (existsSync(absPnpApiPath)) {
	if (!process.versions.pnp) {
		// Setup the environment to be able to import xo
		const { default: pnp } = await import(absPnpApiPath)
		pnp.setup()
	}
}

// Defer to the real xo your application uses
const { getErrorResults, getFormatter, outputFixes, lintText, lintFiles } = await import('xo')
export { getErrorResults, getFormatter, outputFixes, lintText, lintFiles }
EOF

Environment

System:
    OS: Linux 5.14 Arch Linux
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
  Binaries:
    Node: 16.11.1 - /tmp/xfs-4e63bbf9/node
    Yarn: 3.1.0 - /tmp/xfs-4e63bbf9/yarn
    npm: 8.1.3 - /usr/bin/npm

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
yarnbotcommented, Dec 12, 2021

Hi! 👋

This issue looks stale, and doesn’t feature the reproducible label - which implies that you didn’t provide a working reproduction using Sherlock. As a result, it’ll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).

Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we’re a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! 😃

If you absolutely cannot reproduce a bug on Sherlock (for example because it’s a Windows-only issue), a maintainer will have to manually add the upholded label. Thanks for helping us triaging our repository! 🌟

0reactions
flying-sheepcommented, Jan 31, 2022

With node 17.4 we can make progress! See #4045

Read more comments on GitHub >

github_iconTop Results From Across the Web

1664859 – ImportError: cannot import name NoValue
Description of problem: When using v2.5.1 on RHEL 7, I get the following error: ImportError: cannot import name NoValue This stems from the...
Read more >
Cannot import local module in Python despite trying multiple ...
Try from WebScraper.actor import Actor . If this doesn't work its because your package directory is not in the PYTHONPATH .
Read more >
Traps for the Unwary in Python's Import System
While Python 3.3+ is able to import the submodule without any problems: $ python3 -c "import example.foo" Hello from example.foo ...
Read more >
lm393 ltspice
Lm393 LtspiceThey can operate with a supply voltage ranging from 2. LM393B Dual commercial grade standard comparator Data sheet LM393B, LM2903B, LM193, ...
Read more >
Cannot import python libraries in Matlab - MathWorks
The problem is that I get the same error for all of them. For simplicity I share only the error related to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found