Skip to content

MODULE_NOT_FOUND Error #189

Open
Open

Description

@dingiyan

What version of pkg are you using?

6.7.0

What version of Node.js are you using?

24.10.0

What operating system are you using?

Windows

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node22-win-x64

Describe the Bug

the dependence have is-generator-function ^1.1.2 package, then, the build exe file exec error.

pkg/prelude/bootstrap.js:1876
throw error;
^

Error: Cannot find module 'C:\snapshot\pkg-issue-module-not-found-demo\node_modules\generator-function\require.mjs'

  1. If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1423:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1412:15)
    at resolveExports (node:internal/modules/cjs/loader:654:14)
    at Function._findPath (node:internal/modules/cjs/loader:721:31)
    at Function. (node:internal/modules/cjs/loader:1373:27)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1959:46)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1029:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1034:22)
    at Function._load (node:internal/modules/cjs/loader:1196:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
    code: 'MODULE_NOT_FOUND',
    path: 'C:\snapshot\pkg-issue-module-not-found-demo\node_modules\generator-function',
    pkg: true
    }

Expected Behavior

expect the exe file can exec success.

To Reproduce

  1. create one empty npm package npm init
  2. install the packge: npm install is-generator-funciton@^1.1.2
  3. create index.js write code require('is-generator-function')
  4. build by pkg pkg index.js --options experimental-require-module --target=node22-win-x64 -o test.exe
  5. exec the ./test.exe

the package.json:

{
  "name": "pkg-issue-module-not-found-demo",
  "version": "1.0.0",
  "description": "",
  "license": "ISC",
  "author": "",
  "type": "commonjs",
  "main": "index.js",
  "scripts": {
    "test": "node index.js",
    "build": "pkg index.js --options experimental-require-module --target=node22-win-x64 -o test.exe"
  },
  "dependencies": {
    "is-generator-function": "^1.1.2"
  },
  "devDependencies": {
    "@yao-pkg/pkg": "^6.7.0"
  },
  "pkg": {
    "assets": [
      "./node_modules/is-generator-function/**/*.js",
      "./node_modules/is-generator-function/**/*.json",
      "./node_modules/generator-function/**/*.json",
      "./node_modules/generator-function/**/*.js",
      "./node_modules/generator-function/**/*.mjs"
    ]
  }
}

Activity

  1. dingiyan commented on Nov 27, 2025

    @dingiyan
    Author

    I think, the generator-funciton package exports has effect.

    {
    	"name": "generator-function",
    	"version": "2.0.1",
    	"description": "A function that returns the normally hidden `GeneratorFunction` constructor",
    	"main": "./legacy.js",
    	"jsnext:main": "./index.mjs",
    	"module": "./index.mjs",
    	"exports": {
    		".": [
    			{
    				"module-sync": "./require.mjs",
    				"import": "./index.mjs",
    				"default": "./index.js"
    			},
    			"./index.js"
    		],
    		"./package.json": "./package.json"
    	},
    	"sideEffects": false,
    	"scripts": {
    		"prepack": "npmignore --auto --commentLines=autogenerated",
    		"prepublish": "not-in-publish || npm run prepublishOnly",
    		"prepublishOnly": "safe-publish-latest",
    		"pretest": "npm run --silent lint",
    		"test": "npm run tests-only",
    		"posttest": "npx npm@\">=10.2\" audit --production",
    		"tests-only": "nyc tape 'test/**/*.js'",
    		"prelint": "evalmd README.md",
    		"lint": "eslint --ext=js,mjs .",
    		"postlint": "tsc && attw -P",
    		"version": "auto-changelog && git add CHANGELOG.md",
    		"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
    	},
    	"repository": {
    		"type": "git",
    		"url": "git+https://github.com/TimothyGu/generator-function.git"
    	},
    	"keywords": [
    		"generator",
    		"function",
    		"native"
    	],
    	"author": "Jordan Harbamd <ljharb@gmail.com>",
    	"license": "MIT",
    	"bugs": {
    		"url": "https://github.com/TimothyGu/generator-function/issues"
    	},
    	"homepage": "https://github.com/TimothyGu/generator-function#readme",
    	"devDependencies": {
    		"@arethetypeswrong/cli": "^0.18.2",
    		"@ljharb/eslint-config": "^21.2.0",
    		"@ljharb/tsconfig": "^0.3.2",
    		"@types/semver": "^6.2.7",
    		"@types/tape": "^5.8.1",
    		"auto-changelog": "^2.5.0",
    		"encoding": "^0.1.13",
    		"eslint": "=8.8.0",
    		"evalmd": "^0.0.19",
    		"generator-function": "file:.",
    		"get-proto": "^1.0.1",
    		"in-publish": "^2.0.1",
    		"npmignore": "^0.3.1",
    		"nyc": "^10.3.2",
    		"safe-publish-latest": "^2.0.0",
    		"semver": "^6.3.1",
    		"tape": "^5.9.0",
    		"typescript": "next"
    	},
    	"engines": {
    		"node": ">= 0.4"
    	},
    	"auto-changelog": {
    		"output": "CHANGELOG.md",
    		"template": "keepachangelog",
    		"unreleased": false,
    		"commitLimit": false,
    		"backfillLimit": false,
    		"hideCredit": true
    	},
    	"publishConfig": {
    		"ignore": [
    			".github/workflows"
    		]
    	},
    	"testling": {
    		"files": "test/index.js"
    	}
    }
    
    

    because of the package config, when require the module, it shold resolve the commonjs entry index.js, but pkg resolve the require.mjs file, and after, require.mjs import the index.js , it's show module_not_found

  2. emmansun commented on Jan 8, 2026

    @emmansun

    It's similar issue with #195 . Maybe require-module support issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions