What happened:
I installed the package in a node application and imported it in one of my modules.
When I run the app Webpack complains about a missing ./package file.
See "Anything else we need to know?" below to see how I fixed it.
ERROR in ./node_modules/shopify-api-node/index.js 9:12-32
Module not found: Error: Can't resolve './package' in 'shopify-integration/node_modules/shopify-api-node'
resolve './package' in 'shopify-integration/node_modules/shopify-api-node'
using description file: shopify-integration/node_modules/shopify-api-node/package.json (relative path: .)
using description file: shopify-integration/node_modules/shopify-api-node/package.json (relative path: ./package)
no extension
shopify-integration/node_modules/shopify-api-node/package doesn't exist
.tsx
shopify-integration/node_modules/shopify-api-node/package.tsx doesn't exist
.ts
shopify-integration/node_modules/shopify-api-node/package.ts doesn't exist
.js
shopify-integration/node_modules/shopify-api-node/package.js doesn't exist
as directory
node_modules/shopify-api-node/package doesn't exist
@ ./src/modules/commands/fetch-inventory-command.ts 12:16-43
@ ./src/modules/commands/index.js 3:0-66 3:0-66
@ ./src/modules/tasks/create-task-handler.ts 12:0-166 42:30-54 45:30-51 48:30-58 51:30-51 54:30-58
@ ./src/modules/tasks/index.js 1:0-65 1:0-65
@ ./src/index.ts 10:0-134 37:27-51 38:27-53 39:27-49 40:27-50
What you expected to happen:
The package would be able to load successfully and not cause the transpiler to fail the build.
How to reproduce it (as minimally and precisely as possible):
cmd
yarn add shopify-node-api
**.ts
import * as Shopify from 'shopify-node-api';
cmd
yarn run-dev
Anything else we need to know?:
The error occurs because it tries to resolve the const pkg = require('./package'); import as one of the following: js, ts, tsx.
Adding .json to the config.resolve.extensions Webpack config file or explicitly setting the import file type to
json const pkg = require('./package.json'); solves it.
This is Webpack-specific and something that took me long to figure out because I didn't understand why package.json
was being imported. I thought creating the issue may help someone who gets this same error.
As far I can remember this is the first time I add that file extension to the resolved list and that may be the case for someone
else.
webpack.txt
What happened: I installed the package in a node application and imported it in one of my modules. When I run the app Webpack complains about a missing
./package
file. See "Anything else we need to know?" below to see how I fixed it.What you expected to happen: The package would be able to load successfully and not cause the transpiler to fail the build.
How to reproduce it (as minimally and precisely as possible): cmd
**.ts
cmd
Anything else we need to know?: The error occurs because it tries to resolve the
const pkg = require('./package');
import as one of the following: js, ts, tsx. Adding.json
to theconfig.resolve.extensions
Webpack config file or explicitly setting the import file type to jsonconst pkg = require('./package.json');
solves it.This is Webpack-specific and something that took me long to figure out because I didn't understand why package.json was being imported. I thought creating the issue may help someone who gets this same error. As far I can remember this is the first time I add that file extension to the resolved list and that may be the case for someone else. webpack.txt
Environment: