Giter Club home page Giter Club logo

Comments (2)

gcanti avatar gcanti commented on May 24, 2024

docs/examples is a temporary folder used by docs-ts to run all the examples (which are supposed to be valid, including the necessary imports). If there are no errors, it will be deleted by docs-ts, and it is not supposed to be committed.

The error you're receiving is due to the fact that type: "module" is not supported.

As a workaround, you could add the following two files to the /docs folder:

package.json

{
  "name": "examples"
}

tsconfig.json

{
  "compilerOptions": {
    "module": "CommonJS"
    // your other options
  }
}

from docs-ts.

samhh avatar samhh commented on May 24, 2024

@gcanti That doesn't appear to work for me with ESM imports:

// https://www.typescriptlang.org/docs/handbook/esm-node.html
import x from './y.js'

// https://nodejs.org/api/packages.html#subpath-imports
import x from '#self/y'
TSError: ⨯ Unable to compile TypeScript:
docs/examples/src-Alternative.ts-function-pureIf-0.ts(2,24): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("../../src/Alternative")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/path/to/repo/docs/package.json'.

Repro (slightly different files in :/docs/ but easy to adjust): https://github.com/samhh/fp-ts-std/tree/esm (Edit: out of date, but the issue can be repro'd in the repo generally)

Edit: Built a workaround script: samhh/fp-ts-std@4d679d6#diff-11acf79cfa31caef7478b768e28dffb6d7272c308c98f666c529f68bc9685871

from docs-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.