Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Requires Node16/NodeNext? #416

Closed
mrwizard82d1 opened this issue Aug 11, 2022 · 5 comments
Closed

Requires Node16/NodeNext? #416

mrwizard82d1 opened this issue Aug 11, 2022 · 5 comments

Comments

@mrwizard82d1
Copy link

I was trying to work through the "Just the API, please" section of the Setup document.

When I entered the line import Result, { err, map, ok, string } from 'type-script/result';, Webstorm reports that it cannot find the module 'true-myth/result. I confirmed that I had installed true-myth. Additionally, I noticed that Webstore identified the module as coming from 'node_modules/true-myth/dist/public/result.d.ts' which seemed to be correct. (I had created the Webstorm project by executing yarn create react-app --template typescript learn-true-myth`)

The same error occurred in a different environment using an environment with ts-node installed. Finally, I executed the code tsc result-functional.ts | node in my shell and saw the same error.

When I changed the import statement to import Result, { err, map, ok, string } from 'type-script/dist/public/result'; Webstorm reported no error.

What is the correct way to import items from true-myth?

P. S. I'm running on a 64-bit installation of Windows-10. My shell is a Git bash shell running zsh in WSL2.

@mrwizard82d1
Copy link
Author

Here is the output of piping tsc to node:

λ tsc result-functional.ts | node
[stdin]:1
result-functional.ts(1,48): error TS2307: Cannot find module 'true-myth/result' or its corresponding type declarations.
^

SyntaxError: Unexpected token ':'
←[90m at new Script (node:vm:101:7)←[39m
←[90m at createScript (node:vm:258:10)←[39m
←[90m at Object.runInThisContext (node:vm:306:10)←[39m
←[90m at node:internal/process/execution:76:19←[39m
at [stdin]-wrapper:6:22
←[90m at evalScript (node:internal/process/execution:75:60)←[39m
←[90m at node:internal/main/eval_stdin:29:5←[39m
←[90m at Socket. (node:internal/process/execution:213:5)←[39m
←[90m at Socket.emit (node:events:549:35)←[39m
←[90m at endReadableNT (node:internal/streams/readable:1359:12)←[39m

Node.js v18.4.0

@github-actions
Copy link

Thanks so much for filing this issue, and for using True Myth!
This repo is actively supported, but maintainers are busy. One of us will be by soon to give it a look. If you don't hear from us within a week, feel free to give us a gentle nudge.

@mrwizard82d1
Copy link
Author

I seem to encounter similar errors when I try to run jest tests in Webstorm using yarn test.

C:\Users\larry.jones\AppData\Roaming\npm\yarn.cmd test
FAIL src/result-functional.test.ts
● Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.     

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

Details:

C:\src\Brew\Larry\typescript\learn-true-myth\node_modules\true-myth\dist\public\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { Maybe } from './maybe.js';
                                                                                  ^^^^^^

SyntaxError: Unexpected token 'export'

> 1 | import Result from 'true-myth';
    | ^
  2 |
  3 | test('canary test', () => {
  4 |     expect(2 + 2).toEqual(4);

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
  at Object.<anonymous> (src/result-functional.test.ts:1:1)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.948 s
Ran all test suites related to changed files.

@chriskrycho
Copy link
Collaborator

chriskrycho commented Aug 15, 2022

I believe this is a function of your Node and TS configurations, based on the issues you're seeing. Per the release notes for v6, you must:

  • be on Node 14+
  • be on TS 4.7+
  • be using moduleResolution: "Node16" in your tsconfig.json
  • be using type: "module" or using import() to import the files if in a CJS build

If all of those are true and you’re still having this issue, please let us know!

(Related, but not identical: #380)

@kee-oth
Copy link

kee-oth commented Sep 5, 2022

I'm experiencing the same issue. The issue with the true-myth package is resolved if I switch

moduleResolution: "node"

to

moduleResolution: "Node16"

but that breaks a lot of my other imports. Is there a way to have True Myth work with moduleResolution: "node"?

@chriskrycho chriskrycho changed the title Error in Documentation Requires Node16/NodeNext? Sep 7, 2022
@true-myth true-myth locked and limited conversation to collaborators Sep 7, 2022
@chriskrycho chriskrycho converted this issue into discussion #432 Sep 7, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants