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

RedspotError: RS5: RedspotContext is not created. #178

Open
forgetso opened this issue Mar 15, 2022 · 2 comments
Open

RedspotError: RS5: RedspotContext is not created. #178

forgetso opened this issue Mar 15, 2022 · 2 comments

Comments

@forgetso
Copy link
Contributor

forgetso commented Mar 15, 2022

Redspot Version
0.13.6

My project is a module compiling to esnext.

    "target": "esnext",  
    "module": "esnext",  
    "moduleResolution": "node",

I am trying to import redspot using

// myscript.js
const rse = require("redspot");
const {network, patract} = rse

when I hit this error when running node --es-module-specifier-resolution=node myscript.js

/usr/src/packages/provider/packages/contract/node_modules/redspot/internal/context.js:32
            throw new errors_1.RedspotError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED);
                  ^

RedspotError: RS5: RedspotContext is not created.
    at Function.getRedspotContext (/usr/src/packages/provider/packages/contract/node_modules/redspot/internal/context.js:32:19)
    at extendEnvironment (/usr/src/packages/provider/packages/contract/node_modules/redspot/internal/core/config/config-env.js:60:42)
    at Object.<anonymous> (/usr/src/packages/provider/packages/contract/node_modules/@redspot/patract/index.js:13:32)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0) {
  parent: undefined,
  errorDescriptor: {
    number: 5,
    message: 'RedspotContext is not created.',
    title: "Redspot wasn't initialized",
    description: 'Redspot initialization failed. This is a bug.\n' +
      '\n' +
      'Please [report it](https://github.com/nomiclabs/redspot/issues/new) to help us improve Redspot.',
    shouldBeReported: true
  },
  number: 5,
  messageArguments: {},
  _isRedspotError: true
}

If I change to

import { network, patract } from 'redspot'

I get different errors about redspot being commonjs

import { network, patract } from 'redspot';
         ^^^^^^^
SyntaxError: Named export 'network' not found. The requested module 'redspot' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'redspot';
const { network, patract } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:127:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

How can I import redspot into my project?

@forgetso
Copy link
Contributor Author

forgetso commented Mar 15, 2022

Further context

To get my TypeScript project to build I had to put import "@redspot/patract"; at the top of one of my ts files.

Then I was allowed to do this:

import { network, patract } from "redspot"

If I remove import "@redspot/patract";, I get a build error

../contract/src/interface.ts:33:19 - error TS2305: Module '"redspot"' has no exported member 'patract'.

And if I change the import to

import pkg from 'redspot';
const { network, patract } = pkg;

I get a slightly different build error

../contract/src/interface.ts:32:18 - error TS2339: Property 'patract' does not exist on type 'RuntimeEnvironment'.

@forgetso
Copy link
Contributor Author

I have also tried this setting module to commonjs in tsconfig

    "target": "esnext", 
    "module": "commonjs",
    "moduleResolution": "node",

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

No branches or pull requests

1 participant