Skip to content
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

Jest test runner cannot find fullcalendar modules #5467

Closed
sgoodrow opened this issue May 28, 2020 · 16 comments
Closed

Jest test runner cannot find fullcalendar modules #5467

sgoodrow opened this issue May 28, 2020 · 16 comments

Comments

@sgoodrow
Copy link

sgoodrow commented May 28, 2020

Bug

See this repository for reproduction steps: https://github.com/sgoodrow/test-fullcalendar-v5

Clone and run:

  1. yarn install
  2. yarn test
FAIL  src/App.test.js
  ● Test suite failed to run

    Cannot find module '@fullcalendar/react' from 'DemoApp.jsx'

    However, Jest was able to find:
    	'./DemoApp.jsx'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    However, Jest was able to find:
    	'./App.css'
    	'./App.js'
    	'./App.test.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

      1 | import React from "react";
    > 2 | import FullCalendar from "@fullcalendar/react";
        | ^
      3 | import dayGridPlugin from "@fullcalendar/daygrid";
      4 |
      5 | export default class DemoApp extends React.Component {

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
      at Object.<anonymous> (src/DemoApp.jsx:2:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.985s

This repository was created by:

  1. Running create-react-app
  2. Installing the v5 react fullcalendar per these instructions

React/Vue/Angular/etc

I happen to be using React, but the import error occurs for the plugin files, too, so this is a broader issue than just the React connector. AKA, if you change the import order:

import React from "react";
import dayGridPlugin from "@fullcalendar/daygrid";
import FullCalendar from "@fullcalendar/react";

You will see Jest get hung up on daygrid instead:

 FAIL  src/App.test.js
  ● Test suite failed to run

    Cannot find module '@fullcalendar/daygrid' from 'DemoApp.jsx'

    However, Jest was able to find:
    	'./DemoApp.jsx'

Note also that this does not occur with 4.x.

@georgehrke
Copy link

georgehrke commented May 29, 2020

I'm also facing a very similar issue and as far as I can tell this was introduced with beta3 and is related to the change from main to module in the package.json.

See the diff:

2,3c2,3
<   "_from": "@fullcalendar/core@5.0.0-beta.2",
<   "_id": "@fullcalendar/core@5.0.0-beta.2",
---
>   "_from": "@fullcalendar/core@5.0.0-beta.3",
>   "_id": "@fullcalendar/core@5.0.0-beta.3",
5c5
<   "_integrity": "sha512-9U/kk8Y4ackY1XZ1PHvX8rG1olixoKveStXdDsX3FCtKATR8fA/O+4Pd5qyH7nGcih8TrgreUjZ+dB+DEaomqQ==",
---
>   "_integrity": "sha512-oZrxSbtti67V/6h+Jy1bvbwQqOozxuuuH+wO53KKXAd2hyLLmZcJTZ/6aFdtlVEbo2AUN/QD030sbsQSQvasZg==",
11c11
<     "raw": "@fullcalendar/core@5.0.0-beta.2",
---
>     "raw": "@fullcalendar/core@5.0.0-beta.3",
15c15
<     "rawSpec": "5.0.0-beta.2",
---
>     "rawSpec": "5.0.0-beta.3",
17c17
<     "fetchSpec": "5.0.0-beta.2"
---
>     "fetchSpec": "5.0.0-beta.3"
23,26c23,26
<   "_resolved": "https://registry.npmjs.org/@fullcalendar/core/-/core-5.0.0-beta.2.tgz",
<   "_shasum": "30a9cbbbf2d6476568f53cfa1c0746d06daa9660",
<   "_spec": "@fullcalendar/core@5.0.0-beta.2",
<   "_where": "/Users/georgehrke/Desktop/fc-test/2",
---
>   "_resolved": "https://registry.npmjs.org/@fullcalendar/core/-/core-5.0.0-beta.3.tgz",
>   "_shasum": "9f1b3ab22d687ef584fff18bb25d80f71035aef6",
>   "_spec": "@fullcalendar/core@5.0.0-beta.3",
>   "_where": "/Users/georgehrke/Desktop/fc-test/3",
37a38
>     "@fullcalendar/common": "5.0.0-beta.3",
45,49d45
<   "keywords": [
<     "calendar",
<     "event",
<     "full-sized"
<   ],
51c47
<   "main": "main.js",
---
>   "module": "main.js",
57a54
>   "sideEffects": true,
60c57
<   "version": "5.0.0-beta.2"
---
>   "version": "5.0.0-beta.3"

@georgehrke
Copy link

georgehrke commented May 29, 2020

According to one of the maintainers of eslint-plugin-import, module is not a supported nor a standard field:

import-js/eslint-plugin-import#1509 (comment)
import-js/eslint-plugin-import#1509 (comment)

@arshaw ^

@acerix
Copy link
Member

acerix commented May 29, 2020

It sounds like there is some issue here, but I wasn't able to reproduce the error.

When I try yarn test on your repo I get errors about a host not found getaddrinfo ENOTFOUND ....

I also tried following the steps manually:

npx create-react-app my-app
cd my-app
npm install --save @fullcalendar/react@5.0.0-beta.4 @fullcalendar/core@5.0.0-beta.4 @fullcalendar/daygrid@5.0.0-beta.4
yarn install
yarn test

That gets me to a prompt where I can press "a" to run all tests, then the one test runs and it passes. Let me know if I missed something or how to reproduce the error.

@acerix acerix closed this as completed May 29, 2020
@sgoodrow-zymergen
Copy link

Ah, shoot. Let me fix the package-lock, sorry about that.

@sgoodrow
Copy link
Author

I pushed a fix. Sorry about that @acerix, forgot I had an internal NPM registry set on the computer I generated the lockfile from.

@sgoodrow
Copy link
Author

Interesting that your steps to reproduce did not elicit the same behavior... 🤔 I'll have to dig in a bit more then, thanks for checking.

@sgoodrow
Copy link
Author

Oh, @acerix you missed the step where you need to import one of the fullcalendar modules into my-app:

These steps repro:

npx create-react-app my-app
cd my-app
npm install --save @fullcalendar/react@5.0.0-beta.4 @fullcalendar/core@5.0.0-beta.4 @fullcalendar/daygrid@5.0.0-beta.4
yarn install
(echo 'import FullCalendar from "@fullcalendar/react";' && cat ./src/App.js) > updated && mv updated ./src/App.js
CI=true; yarn test

error

 FAIL  src/App.test.js
  ● Test suite failed to run

    Cannot find module '@fullcalendar/react' from 'App.js'

    However, Jest was able to find:
    	'./App.css'
    	'./App.js'
    	'./App.test.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    > 1 | import FullCalendar from "@fullcalendar/react";
        | ^
      2 | import React from "react";
      3 | import logo from "./logo.svg";
      4 | import "./App.css";

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
      at Object.<anonymous> (src/App.js:1:1)

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

@sgoodrow-zymergen
Copy link

Any chance this will be reopened? Happy Monday 😁

@acerix acerix reopened this Jun 1, 2020
@acerix acerix changed the title 5.0.0-beta4 Jest test runner cannot find fullcalendar modules Jest test runner cannot find fullcalendar modules Jun 2, 2020
@acerix
Copy link
Member

acerix commented Jun 2, 2020

Thanks for the info, I was able to reproduce the error. It seems like it may be an issue specific to Jest.

@arshaw arshaw added this to the v5-beta5 milestone Jun 5, 2020
@arshaw
Copy link
Member

arshaw commented Jun 5, 2020

in the package.json of each package I specified a module only, because I assumed all environments that are able to consume ES modules would know to look for this, but apparently node-only environments like jest don't. I'll just add a main back in, I don't see any harm in that. will solve this issue.

@ghost
Copy link

ghost commented Jun 8, 2020

Is there a known workaround for this that I can implement temporarily?

@arshaw
Copy link
Member

arshaw commented Jun 16, 2020

This is released in the v5 release candidate

All packages simply use a main field now. If there are further problems, please open a new ticket.

@arshaw arshaw closed this as completed Jun 16, 2020
@ghost
Copy link

ghost commented Jun 24, 2020

Same repo, same commands, similar error:

● Test suite failed to run

    /private/tmp/test-fullcalendar-v5/node_modules/@fullcalendar/react/dist/main.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { __assign, __extends } from "tslib";
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

Reproduce:

  • Pull repo in @sgoodrow-zymergen 's ticket
  • yarn
  • Update deps with yarn upgrade (ensure you see full-calendar is now on v5 rc)
  • yarn test

@arshaw
Copy link
Member

arshaw commented Jun 25, 2020

@chriswall-aa, that is due to Jest not supporting ES6 modules very well.
jestjs/jest#4842

It's rather easy to add babel to your own testing code to have it transpile ESM to CJS, but you'll also need to add it for ./node_modules/@fullcalendar/*

@duhseekoh
Copy link

It's that node doesn't support ES6 modules and jest runs on node. A convention I've seen/used for this is to output an esm and commonjs variant in the bundled npm package.

"main": "./dist/commonjs/index.js",
"types": "./dist/esm/index.d.ts",
"module": "./dist/esm/index.js",

jest running on node will pull in main while something like webpack will pull in module. then the consumer of your package will not need to worry about transpilation of your code.

soon, we'll all live in a world where we can drop commonjs and use import/export exclusively. until then, please output these two variants 🙏

@atifsyedali
Copy link

Agree with @duhseekoh. I was stuck on this for the entire day today trying to make it work, still with no solution. I don't use next.js so cannot do what other issues suggest. Please output two variants. github.com/elastic/ui does it so there's a good example.

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

No branches or pull requests

7 participants