The Challenge
Hello everyone,
I am currently working with TypeScript 3.0.3 and cypress, and I'm facing an issue while trying to import the react-relay-network-modern
module in my component. Despite having the module present in my node_modules folder and also defined in my package.json, I keep getting an error stating that the module doesn't exist. Interestingly, there are no issues when importing relay-runtime
and I have successfully integrated relay into my project.
Whenever I attempt a standard import like this:
import * as RelayNetworkModern from 'react-relay-network-modern';
I encounter the following error indicating that the module was not found.
/src/relayEnvironment.ts
[tsl] ERROR in /src/relayEnvironment.ts(8,37)
TS2307: Cannot find module 'react-relay-network-modern'.
Even after setting up aliases both in my tsconfig.json and webpack preprocessor or trying to import subfolders within
react-relay-network-modern/(es|lib|...)
, the same errors persist.
Configuration Details
Let me share my configuration files with you:
/cypress/plugins/webpack.config.js
const webpack = require( '@cypress/webpack-preprocessor' );
const path = require('path');
const options = {
watchOptions: {},
webpackOptions: {
resolve: {
extensions: [ '.web.js', '.js', '.json', '.web.jsx', '.jsx', '.tsx', '.ts', '.mjs' ],
modules: [
path.resolve( __dirname, '../../node_modules' ),
path.resolve( __dirname, '../../src' ),
],
alias: {
'react-relay-network-modern': path.resolve( __dirname, '../../node_modules/react-relay-network-modern/es' ),
src: path.resolve( __dirname, '../../src' ),
}
},
module: {
rules: [
{
type: 'javascript/auto',
test: /\.mjs$/,
include: /node_modules/,
use: [],
},
{
test: /\.ts(x)?$/,
exclude: [ /node_modules/ ],
use: [
{
loader: 'babel-loader',
options: {
presets: [ '@babel/preset-react' ],
plugins: [ 'relay' ],
},
},
{
loader: 'ts-loader',
},
],
},
],
},
},
};
module.exports = webpack( options );
/tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"target": "es6",
"jsx": "react",
"skipLibCheck": true,
"noImplicitAny": false,
"strict": true,
"lib": ["dom", "es6", "es2016", "es2017.object"],
"types": [ "cypress", "react" ],
"typeRoots": [ "node_modules/@types", "types" ],
"paths" : {
"react": ["node_modules/@types/react"],
"react-relay-network-modern": ["node_modules/react-relay-network-modern/es"],
"src/*": ["src/*"],
"components/*": ["src/*"]
}
},
"include": [
"node_modules/cypress",
"src/*/*.ts"
]
}