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

typescript: import spacetime from ('spacetime') says undefined #144

Closed
avishaan opened this issue Jun 5, 2019 · 8 comments
Closed

typescript: import spacetime from ('spacetime') says undefined #144

avishaan opened this issue Jun 5, 2019 · 8 comments

Comments

@avishaan
Copy link

avishaan commented Jun 5, 2019

I'm relatively new to typescript by my other dependencies are working ok. I have the following error when using this module import method

image

but no error when using this method
image

my tslinter is complaining about the 2nd one but other than that it is working. something you may want to look into, not sure if it's specific to me

@avishaan avishaan changed the title typescript 'import spacetime from 'spacetime' says undefined typescript import spacetime from 'spacetime' says undefined Jun 5, 2019
@avishaan avishaan changed the title typescript import spacetime from 'spacetime' says undefined typescript: import spacetime from ('spacetime') says undefined Jun 5, 2019
@jecraig
Copy link
Contributor

jecraig commented Jun 5, 2019

@codehatcher Can you paste in your tsconfig

@avishaan
Copy link
Author

avishaan commented Jun 5, 2019

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true,
    "sourceMap": true
  }
}

@jecraig
Copy link
Contributor

jecraig commented Jun 5, 2019

Ok, so I think this is just an issue with the way your typescript is configured. You've got commonjs which uses

const x = require('y')

which overrides with the es6 import syntax (typescripts default syntax)

import x from 'y'

So either remove the module option from your tsconfig or just continue using the commonjs require syntax.

I don't think there's any issues with spacetime though.

@avishaan
Copy link
Author

I appreciate you troubleshooting this with me @jecraig, I changed the tsconfig as you suggested and now get a slightly different error

I tried one where I switched to the following tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "es6",
    "declaration": true,
    "outDir": "./dist",
    "strict": true,
    "sourceMap": true
  }
}

and get the following error
image

@avishaan
Copy link
Author

As i'm looking through these test cases I see there is nothing that uses the typescript non-relative resolution via a string literal e.g. import spacetime from 'spacetime' but rather in the test file as import { spacetime } from './spacetime-static'

@avishaan
Copy link
Author

what's weird is it does have spacetime_1 when I debug and that seems to be the correct function, but nothing still called spacetime that seems to be imported

image

which is when I run the debugger with the following code

image

@jecraig
Copy link
Contributor

jecraig commented Jun 12, 2019

I scratched up a quick project and there do appear to be some issues using the typings without a bundler. I've been using Spacetime with Webpack no problem. I'll try looking into some solutions for using it without a bundler.

@spencermountain
Copy link
Owner

version 5.1.0 ships a .mjs build, that is linked in package.json.
so this should be working now. lemme know if there's still any weird issues.
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants