Skip to content

Pkg cannot resolve JSON modules #34

@CMCDragonkai

Description

@CMCDragonkai

Describe the bug

When doing nix-build ./release.nix -A package.linux.x64.elf or any of the executable builds, it results in:

> Warning Cannot find module './test.json' from '/build/typescript-demo-lib/dist'  in /build/typescript-demo-lib/dist/utils.js

The test.json is currently in src/test.json which is imported by src/utils.ts.

The TSC compiles it properly and we see that src/test.json is in dist/test.json.

Even if I add dist/test.json to assets or scripts it doesn't work. And the resulting executable throws a MODULE_NOT_FOUND error.

CMCDragonkai | POLYHACK-SURF2 | C:\Users\CMCDragonkai\Downloads
 > .\9i6jr0lxji4l99gc0sw8sfpp5b6inhn3-typescript-demo-lib-1.1.2-win32-x64.exe
pkg/prelude/bootstrap.js:1697
      throw error;
      ^

Error: Cannot find module './test.json'
Require stack:
- C:\snapshot\typescript-demo-lib\dist\utils.js
- C:\snapshot\typescript-demo-lib\dist\lib\test-utp-native.js
- C:\snapshot\typescript-demo-lib\dist\bin\typescript-demo-lib.js
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 Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1776:46)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at Module.require (pkg/prelude/bootstrap.js:1676:31)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\snapshot\typescript-demo-lib\dist\utils.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Module._compile (pkg/prelude/bootstrap.js:1758:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\snapshot\\typescript-demo-lib\\dist\\utils.js',
    'C:\\snapshot\\typescript-demo-lib\\dist\\lib\\test-utp-native.js',
    'C:\\snapshot\\typescript-demo-lib\\dist\\bin\\typescript-demo-lib.js'
  ],
  pkg: true
}

To Reproduce

  1. nix-build ./release.nix -A package.linux.x64.elf
  2. Watch the logs
  3. Download executable to windows and execute it

Expected behavior

The pkg should be bundling the test.json as normal.

Note that package.json does not appear to be a problem.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions