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/resolver-default: External dependency "crypto" is not declared in package.json. #9843

Open
zhfnjust opened this issue Jul 11, 2024 · 1 comment

Comments

@zhfnjust
Copy link

zhfnjust commented Jul 11, 2024

🐛 bug report

@parcel/resolver-default: External dependency "crypto" is not declared in package.json.

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

{
  "name": "@scrypt/ssapp",
  "version": "1.0.0",
  "source": "src/index.js",
  "main": "dist/main.js",
  "module": "dist/module.js",
  "browser": "dist/browser.js",
  "types": "index.d.ts",
  "alias": {
    "process": "process/browser.js",
    "assert": "assert",
    "crypto": "crypto-browserify"
  },
  "targets": {
    "types": false
  },
  "scripts": {
    "watch": "parcel watch",
    "build": "parcel build --no-cache",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "assert": "^2.1.0",
    "crypto-browserify": "^3.12.0",
    "path-browserify": "^1.0.1",
    "process": "^0.11.10"
  },
  "devDependencies": {
    "parcel": "^2.12.0"
  }
}

🤔 Expected Behavior

Build success.

😯 Current Behavior

Build failed.

@parcel/core: Failed to resolve 'crypto' from './src/index.js'

C:\Users\myland\code\tmp\ssApp\src\index.js:2:28
1 | import { join } from "path";

2 | import { createHash } from 'crypto'
| ^^^^^^^^
3 | import { readFileSync } from 'fs'
4 | import assert from "assert";

@parcel/resolver-default: External dependency "crypto" is not declared in package.json.

C:\Users\myland\code\tmp\ssApp\package.json:26:3
25 | "description": "",

26 | "dependencies": {
| ^^^^^^^^^^^^^^
27 | "assert": "^2.1.0",
28 | "crypto-browserify": "^3.12.0",

💡 Add "crypto" as a dependency.

💁 Possible Solution

🔦 Context

💻 Code Sample

import { join } from "path";
import { createHash } from 'crypto'
import { readFileSync } from 'fs'
import assert from "assert";
export function add(a, b) {
    return a + b;
}


export function getaa() {
    return join("/asdfasdf/adfasdf", 'asdfas');
}

export function myhash(str) {
    assert.deepEqual(str, "aa")
    console.log('myhash', str, process.env)
    console.log('aaa', readFileSync(join("aa", "aa.txt")).toString())
    return createHash('sha256').update(str).digest('hex');
}


export default {
    add,
    getaa,
    myhash
}

🌍 Your Environment

Software Version(s)
Parcel 2.12.0
Node v18.17.0
npm/Yarn npm 9.6.7
Operating System windows
@zhfnjust
Copy link
Author

this error only happened when i use parcel version >= v2.9.0

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

1 participant