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

Can not import third party libraries in the node-modules in .tsx file #182

Closed
cindyliu-yb opened this issue Sep 25, 2017 · 2 comments
Closed

Comments

@cindyliu-yb
Copy link

Stencil version: (run npm list @stencil/core from a terminal/cmd prompt and paste output below):

@stencil/[email protected] 
├── @stencil/[email protected]
└─┬ @stencil/[email protected]
  └── @stencil/[email protected]

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
I cannot import any third-party libraries in .tsx files.

Expected behavior:
I should be able to import third-party libraries and use them in a component class.

Steps to reproduce:

  1. initiate a stencil-starter project and install moment library 'npm install --save momet'
  2. run 'npm start'
  3. Go to src/components/my-name/my-name.tsx to import moment
  4. If using moment to convert a date format and assign the value to a public variable, in the terminal the compiler will start rebuilding but get stuck at "prerender index html started"
  5. If using moment to convert a date format and assign the value to a public variable in componentWillLoad lifecycle, in the terminal the compiler will be able to rebuild but have the error that
           moment is not defined

Related code:
In my-name.tsx

import { Component, Prop, State } from '@stencil/core';
import { Element } from '@stencil/core';
import * as moment from 'moment';

@Component({
  tag: 'my-name',
  styleUrl: 'my-name.scss'
})
export class MyName {
    currentTime: any = moment(new Date()).format('YYYY-MM-DD');

    render() {
      return (
       <div>
         <div> Current time is { this.currentTime }</div>
       </div>
    );
  }
}

Thanks!

@mortenson
Copy link

mortenson commented Oct 2, 2017

I'm seeing this too, but I'm not sure what the ideal DX is for a solution. Maybe Stencil could see if a third party library is imported by a component and package it in dist/ if so?

Edit: I don't have this problem, but I'm not using moment or my third party library in the same way. Ignore comment above.

@jgw96
Copy link
Contributor

jgw96 commented Oct 2, 2017

Hello all! We are going to fix this with #162 . Thanks for opening an issue with us and welcome to the land of web components!

@jgw96 jgw96 closed this as completed Oct 2, 2017
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

3 participants