jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.21k stars 505 forks source link

`tsdx build` not configured to allow json imports with array at root #1042

Closed d-w-d closed 3 years ago

d-w-d commented 3 years ago

Current Behavior

importing a json file with top-level array as follows within a .ts file:

import jsonData from './path/to/file.json';

... leads to the following error when I run tsdx build:

Error: 'default' is not exported by path/to/file.json, imported by path/to/file.ts

When I wrap the array in the json with {"data":[]}, it works. JSON is supposed to allow for arrays at root, and not require one to have access to the JSON file in order to wrap it as an object at root.

Expected behavior

imports JSON as array on build without error.

Suggested solution(s)

Not sure -- might be a default rollup config.

Your environment


    "tsdx": "^0.14.1"

  System:
    OS: macOS 11.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 668.88 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    npm: 7.14.0 - ~/.nvm/versions/node/v14.17.0/bin/npm
  Browsers:
    Brave Browser: 90.1.24.82
    Chrome: 91.0.4472.77
    Firefox: 88.0.1
    Safari: 14.1.1
  npmPackages:
    tsdx: ^0.14.1 => 0.14.1
    typescript: ^3.9.9 => 3.9.9
  npmGlobalPackages:
    typescript: 4.2.4
d-w-d commented 3 years ago

Never mind. It does accept arrays; however, the output message was misleading, the actual problem is that the final object within the array had a trailing comma. So whereas the message suggested that the problem was due to misconfiguration with importing json, the actual problem was invalid json formatting.