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

Updating Package.json Type from Module to CommonJS #35

Merged

Conversation

stephenyu
Copy link
Contributor

Was trying to run npm run test which invokes the test server however it was failing due to:

07:06:42 ~/P/web-vitals master origin/master ✓
~ npm run test

> [email protected] test /Users/stephenyu/Personal/web-vitals
> npm-run-all build -p -r test:*


> [email protected] build /Users/stephenyu/Personal/web-vitals
> run-s clean build:ts build:js


> [email protected] clean /Users/stephenyu/Personal/web-vitals
> rm -rf dist tsconfig.tsbuildinfo


> [email protected] build:ts /Users/stephenyu/Personal/web-vitals
> tsc -b


> [email protected] build:js /Users/stephenyu/Personal/web-vitals
> rollup -c

loaded rollup.config.js with warnings
(!) Unused external imports
default imported from external module 'fs-extra' but never used

dist/index.js → ./dist/web-vitals.es5.min.js...
created ./dist/web-vitals.es5.min.js in 808ms

dist/index.js → ./dist/web-vitals.es5.umd.min.js...
created ./dist/web-vitals.es5.umd.min.js in 480ms

> [email protected] test:e2e /Users/stephenyu/Personal/web-vitals
> wdio wdio.conf.js


> [email protected] test:server /Users/stephenyu/Personal/web-vitals
> node test/server.js

internal/modules/cjs/loader.js:1174
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/stephenyu/Personal/web-vitals/test/server.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1174:13)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'ERR_REQUIRE_ESM'
}

This is due to the require statements within server.js.

This PR changes the package.json type declaration to commonjs which seems to have done the trick and npm run test and npm run test:server works.

@stephenyu stephenyu changed the title Updating Module to CommonJS Updating Package.json Type from Module to CommonJS May 12, 2020
package.json Outdated Show resolved Hide resolved
@stephenyu stephenyu requested a review from philipwalton May 12, 2020 22:17
Copy link
Member

@philipwalton philipwalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@philipwalton philipwalton merged commit 754b855 into GoogleChrome:master May 12, 2020
@stephenyu stephenyu deleted the stephenyu-package-json-commonjs branch May 12, 2020 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants