I’ve also confirmed that I’ve got node-fetch installed in the package.json in my /api directory, however whenever I try to access the service I get the following message about the node-fetch import.
yarn run v1.22.10
$ /workspaces/force-redwood-test/node_modules/.bin/rw dev
$ /workspaces/force-redwood-test/node_modules/.bin/cross-env NODE_ENV=development NODE_OPTIONS=--enable-source-maps yarn nodemon --watch /workspaces/force-redwood-test/redwood.toml --exec 'yarn rw-api-server-watch'
$ /workspaces/force-redwood-test/node_modules/.bin/cross-env NODE_ENV=development RWJS_WATCH_NODE_MODULES= webpack serve --config /workspaces/force-redwood-test/node_modules/@redwoodjs/core/config/webpack.development.js
$ /workspaces/force-redwood-test/node_modules/.bin/rw-gen-watch
$ /workspaces/force-redwood-test/node_modules/.bin/nodemon --watch /workspaces/force-redwood-test/redwood.toml --exec 'yarn rw-api-server-watch'
api | [nodemon] 2.0.15
api | [nodemon] to restart at any time, enter `rs`
api | [nodemon] watching path(s): redwood.toml
api | [nodemon] watching extensions: js,mjs,json
api | [nodemon] starting `yarn rw-api-server-watch`
$ /workspaces/force-redwood-test/node_modules/.bin/rw-api-server-watch
gen | Generating TypeScript definitions and GraphQL schemas...
gen | 31 files generated
api | Building... Took 407 ms
api | Starting API Server...Importing Server Functions...
api | /healthz 1 ms
api | Took 194 ms
api | Listening on http://localhost:8911/
api | INFO [2022-01-05 21:36:39.464 +0000]: Server listening at http://[::]:8911
api | (node:10337) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /workspaces/force-redwood-test/api/node_modules/node-fetch/src/index.js
api | require() of ES modules is not supported.
api | require() of /workspaces/force-redwood-test/api/node_modules/node-fetch/src/index.js from /workspaces/force-redwood-test/api/dist/services/sfCases/sfCases.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
api | Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /workspaces/force-redwood-test/api/node_modules/node-fetch/package.json.
api |
api | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)
api | at Module.load (internal/modules/cjs/loader.js:937:32)
api | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
api | at Module.require (internal/modules/cjs/loader.js:961:19)
api | at require (internal/modules/cjs/helpers.js:92:18)
api | at Object.<anonymous> (/workspaces/force-redwood-test/api/src/services/sfCases/sfCases.js:2:19)
api | at Module._compile (internal/modules/cjs/loader.js:1072:14)
api | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
api | at Module.load (internal/modules/cjs/loader.js:937:32)
api | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
api | (Use `node --trace-warnings ...` to show where the warning was created)
api | (node:10337) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
api | (node:10337) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Does this make sense to anyone else? For reference I’m using Redwood.js v0.39.4 with Node v14.17.6.
Printing that out I do realize I need to update Redwood. I’ll do that and update this question.
Just upgraded to the latest version and it still looks to be broken.
api | Building... Took 398 ms
api | Starting API Server...Importing Server Functions...
api | /healthz 1 ms
api | Took 178 ms
api | Listening on http://localhost:8911/
api | (node:17508) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /workspaces/force-redwood-test/api/node_modules/node-fetch/src/index.js
api | require() of ES modules is not supported.
api | require() of /workspaces/force-redwood-test/api/node_modules/node-fetch/src/index.js from /workspaces/force-redwood-test/api/dist/services/sfCases/sfCases.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
api | Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /workspaces/force-redwood-test/api/node_modules/node-fetch/package.json.
api |
api | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)
api | at Module.load (internal/modules/cjs/loader.js:937:32)
api | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
api | at Module.require (internal/modules/cjs/loader.js:961:19)
api | at require (internal/modules/cjs/helpers.js:92:18)
api | at Object.<anonymous> (/workspaces/force-redwood-test/api/src/services/sfCases/sfCases.js:2:19)
api | at Module._compile (internal/modules/cjs/loader.js:1072:14)
api | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
api | at Module.load (internal/modules/cjs/loader.js:937:32)
api | at Function.Module._load (internal/modules/cjs/loader.js:778:12)
api | (Use `node --trace-warnings ...` to show where the warning was created)
api | (node:17508) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
api | (node:17508) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.